diff options
Diffstat (limited to 'apps/misc.c')
-rw-r--r-- | apps/misc.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/apps/misc.c b/apps/misc.c index 5b20b35c17..d7d4bdd2f9 100644 --- a/apps/misc.c +++ b/apps/misc.c | |||
@@ -1075,6 +1075,37 @@ void format_time(char* buf, int buf_size, long t) | |||
1075 | } | 1075 | } |
1076 | } | 1076 | } |
1077 | 1077 | ||
1078 | /** | ||
1079 | * Splits str at each occurence of split_char and puts the substrings into vector, | ||
1080 | * but at most vector_lenght items. Empty substrings are ignored. | ||
1081 | * | ||
1082 | * Modifies str by replacing each split_char following a substring with nul | ||
1083 | * | ||
1084 | * Returns the number of substrings found, i.e. the number of valid strings | ||
1085 | * in vector | ||
1086 | */ | ||
1087 | int split_string(char *str, const char split_char, char *vector[], const int vector_length) | ||
1088 | { | ||
1089 | int i; | ||
1090 | char *p = str; | ||
1091 | |||
1092 | /* skip leading splitters */ | ||
1093 | while(*p == split_char) p++; | ||
1094 | |||
1095 | /* *p in the condition takes care of trailing splitters */ | ||
1096 | for(i = 0; p && *p && i < vector_length; i++) | ||
1097 | { | ||
1098 | vector[i] = p; | ||
1099 | if ((p = strchr(p, split_char))) | ||
1100 | { | ||
1101 | *p++ = '\0'; | ||
1102 | while(*p == split_char) p++; /* skip successive splitters */ | ||
1103 | } | ||
1104 | } | ||
1105 | |||
1106 | return i; | ||
1107 | } | ||
1108 | |||
1078 | 1109 | ||
1079 | /** Open a UTF-8 file and set file descriptor to first byte after BOM. | 1110 | /** Open a UTF-8 file and set file descriptor to first byte after BOM. |
1080 | * If no BOM is present this behaves like open(). | 1111 | * If no BOM is present this behaves like open(). |