aboutsummaryrefslogtreecommitdiffstats
path: root/String.c
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2016-04-11 13:00:22 +0200
committerDaniel Lange <DLange@git.local>2016-04-11 13:00:22 +0200
commitc74c38760df69bb87e93dff18cf91464e5d02f37 (patch)
treeee2a19a0ef3a808bdfc8c1e6a00e96d79966dcb0 /String.c
parent9379132a8234eeedf62d37ef57713e52c12db6ab (diff)
downloaddebian_htop-c74c38760df69bb87e93dff18cf91464e5d02f37.tar.gz
debian_htop-c74c38760df69bb87e93dff18cf91464e5d02f37.tar.bz2
debian_htop-c74c38760df69bb87e93dff18cf91464e5d02f37.zip
Imported Upstream version 0.8.1upstream/0.8.1
Diffstat (limited to 'String.c')
-rw-r--r--String.c82
1 files changed, 27 insertions, 55 deletions
diff --git a/String.c b/String.c
index e0b981c..99b2770 100644
--- a/String.c
+++ b/String.c
@@ -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));
+}

© 2014-2024 Faster IT GmbH | imprint | privacy policy