sds icon indicating copy to clipboard operation
sds copied to clipboard

Use of _ in string causes sdssplitlen() to return no tokens

Open k1mgy opened this issue 6 years ago • 1 comments

Thank you for a fantastic library!!

One minor possible issue:

I am using sdssplitlen() to parse out the elements of a path+file string, as in: /DIR1/DIR2/this_isafile.txt <-- cTempString

tokens = sdssplitlen(cTempString,sdslen(cTempString),"/",1,&count);

With an underscore in the string, sdssplitlen() returns NULL.

Haven't single-step debugged it yet. For now, avoiding using filenames with _

k1mgy avatar Jun 08 '19 22:06 k1mgy

I am not sure if this helps or not, but seems to work ok.

#include <stdio.h> #include <stdlib.h> #include <string.h> #include "sds.h" #include "sdsalloc.h"

int main( int argc, char *argv[] ) {

sds *tokens; int count, j; FILE *fp; char path[10350];

/* Open the command for reading. */ fp = popen("/usr/bin/find /home/user/Desktop/|tr '/' '_'", "r"); if (fp == NULL) { printf("Failed to run command\n" ); exit(1); }

/* Read the output a line at a time - output it. */ while (fgets(path, sizeof(path)-1, fp) != NULL) { { sds y = sdsnew(path); printf("%s",y); sds line = sdsnew(y); tokens = sdssplitlen(line,sdslen(line),"home_user",9,&count); for (j = 0; j < count; j++) printf("%s\n", tokens[j]); sdsfreesplitres(tokens,count); }}

/* close */ pclose(fp); return 0; }

msgoff avatar Jun 15 '19 06:06 msgoff