| 6913 | } |
| 6914 | |
| 6915 | char** hb_str_vsplit( const char *str, char delem ) |
| 6916 | { |
| 6917 | const char * pos; |
| 6918 | const char * end; |
| 6919 | char ** ret; |
| 6920 | int count, i; |
| 6921 | char quote = '"'; |
| 6922 | |
| 6923 | if (delem == '"') |
| 6924 | { |
| 6925 | quote = '\''; |
| 6926 | } |
| 6927 | if ( str == NULL || str[0] == 0 ) |
| 6928 | { |
| 6929 | ret = malloc( sizeof(char*) ); |
| 6930 | if ( ret == NULL ) return ret; |
| 6931 | *ret = NULL; |
| 6932 | return ret; |
| 6933 | } |
| 6934 | |
| 6935 | // Find number of elements in the string |
| 6936 | count = 1; |
| 6937 | pos = str; |
| 6938 | while ( ( pos = strchr_quote( pos, delem, quote ) ) != NULL ) |
| 6939 | { |
| 6940 | count++; |
| 6941 | pos++; |
| 6942 | } |
| 6943 | |
| 6944 | ret = calloc( ( count + 1 ), sizeof(char*) ); |
| 6945 | if ( ret == NULL ) return ret; |
| 6946 | |
| 6947 | pos = str; |
| 6948 | for ( i = 0; i < count - 1; i++ ) |
| 6949 | { |
| 6950 | end = strchr_quote( pos, delem, quote ); |
| 6951 | ret[i] = strndup_quote(pos, quote, end - pos); |
| 6952 | pos = end + 1; |
| 6953 | } |
| 6954 | ret[i] = strndup_quote(pos, quote, strlen(pos)); |
| 6955 | |
| 6956 | return ret; |
| 6957 | } |
| 6958 | |
| 6959 | void hb_str_vfree( char **strv ) |
| 6960 | { |