Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
k1mgy opened this issue Jun 8, 2019 · 1 comment
Open

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

k1mgy opened this issue Jun 8, 2019 · 1 comment

Comments

@k1mgy
Copy link

k1mgy commented Jun 8, 2019

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 _

@msgoff
Copy link

msgoff commented Jun 15, 2019

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants