diff options
author | Eugene V. Lyubimkin <jackyf.devel@gmail.com> | 2008-11-16 20:36:18 +0200 |
---|---|---|
committer | Daniel Lange <DLange@git.local> | 2016-04-11 13:00:23 +0200 |
commit | bcb965d78ae0b4599fe77a2d641b3ff035658fc9 (patch) | |
tree | 59066e7fa5473b02eefaea37ac015cfaea7cd7c6 /String.c | |
parent | 2eabf3432b05b93ce4de9af283ae549d0f7c18c8 (diff) | |
parent | c74c38760df69bb87e93dff18cf91464e5d02f37 (diff) | |
download | debian_htop-bcb965d78ae0b4599fe77a2d641b3ff035658fc9.tar.gz debian_htop-bcb965d78ae0b4599fe77a2d641b3ff035658fc9.tar.bz2 debian_htop-bcb965d78ae0b4599fe77a2d641b3ff035658fc9.zip |
Imported Debian patch 0.8.1-1debian/0.8.1-1
Diffstat (limited to 'String.c')
-rw-r--r-- | String.c | 82 |
1 files changed, 27 insertions, 55 deletions
@@ -18,10 +18,6 @@ in the source distribution for its full text. #define String_startsWith(s, match) (strstr((s), (match)) == (s)) }*/ -inline void String_delete(char* s) { - free(s); -} - inline char* String_copy(char* orig) { return strdup(orig); } @@ -49,53 +45,6 @@ char* String_trim(char* in) { return out; } -char* String_copyUpTo(char* orig, char upTo) { - int len; - - int origLen = strlen(orig); - char* at = strchr(orig, upTo); - if (at != NULL) - len = at - orig; - else - len = origLen; - char* copy = (char*) malloc(len+1); - strncpy(copy, orig, len); - copy[len] = '\0'; - return copy; -} - -char* String_sub(char* orig, int from, int to) { - char* copy; - int len; - - len = strlen(orig); - if (to > len) - to = len; - if (from > len) - to = len; - len = to-from+1; - copy = (char*) malloc(len+1); - strncpy(copy, orig+from, len); - copy[len] = '\0'; - return copy; -} - -void String_println(char* s) { - printf("%s\n", s); -} - -void String_print(char* s) { - printf("%s", s); -} - -void String_printInt(int i) { - printf("%i", i); -} - -void String_printPointer(void* p) { - printf("%p", p); -} - inline int String_eq(const char* s1, const char* s2) { if (s1 == NULL || s2 == NULL) { if (s1 == NULL && s2 == NULL) @@ -144,10 +93,6 @@ void String_freeArray(char** s) { free(s); } -int String_startsWith_i(char* s, char* match) { - return (strncasecmp(s, match, strlen(match)) == 0); -} - int String_contains_i(char* s, char* match) { int lens = strlen(s); int lenmatch = strlen(match); @@ -158,3 +103,30 @@ int String_contains_i(char* s, char* match) { } return 0; } + +char* String_getToken(const char* line, const unsigned short int numMatch) { + const unsigned short int len = strlen(line); + char inWord = 0; + unsigned short int count = 0; + char match[50]; + + unsigned short int foundCount = 0; + + for (unsigned short int i = 0; i < len; i++) { + char lastState = inWord; + inWord = line[i] == ' ' ? 0:1; + + if (lastState == 0 && inWord == 1) + count++; + + if(inWord == 1){ + if (count == numMatch && line[i] != ' ' && line[i] != '\0' && line[i] != '\n' && line[i] != EOF) { + match[foundCount] = line[i]; + foundCount++; + } + } + } + + match[foundCount] = '\0'; + return((char*)strdup(match)); +} |