diff options
author | jsorg71 <jsorg71> | 2007-10-27 05:53:19 +0000 |
---|---|---|
committer | jsorg71 <jsorg71> | 2007-10-27 05:53:19 +0000 |
commit | d3fa8fd6f6cefaf61898af30655124b921602318 (patch) | |
tree | 54da10054fff3edf1dacdc55bc390090637dca0c | |
parent | ca37e8cb1d0c697a2b0b63afe9101a570ba2fb2a (diff) | |
download | xrdp-proprietary-d3fa8fd6f6cefaf61898af30655124b921602318.tar.gz xrdp-proprietary-d3fa8fd6f6cefaf61898af30655124b921602318.zip |
added g_strtrim
-rw-r--r-- | common/file.c | 2 | ||||
-rw-r--r-- | common/os_calls.c | 119 | ||||
-rw-r--r-- | common/os_calls.h | 2 |
3 files changed, 123 insertions, 0 deletions
diff --git a/common/file.c b/common/file.c index 6d69d874..f3fa88f1 100644 --- a/common/file.c +++ b/common/file.c @@ -188,6 +188,8 @@ file_split_name_value(char* text, char* name, char* value) name[name_index] = 0; } } + g_strtrim(name, 3); /* trim both right and left */ + g_strtrim(value, 3); /* trim both right and left */ return 0; } diff --git a/common/os_calls.c b/common/os_calls.c index 270ff323..f0d83da3 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -1199,6 +1199,125 @@ g_wcstombs(char* dest, const twchar* src, int n) } /*****************************************************************************/ +/* returns error */ +/* trim spaces and tabs, anything <= space */ +/* trim_flags 1 trim left, 2 trim right, 3 trim both, 4 trim through */ +/* this will always shorten the string or not change it */ +int APP_CC +g_strtrim(char* str, int trim_flags) +{ + int index; + int len; + int text1_index; + int got_char; + wchar_t* text; + wchar_t* text1; + + len = mbstowcs(0, str, 0); + if (len < 1) + { + return 0; + } + if ((trim_flags < 1) || (trim_flags > 4)) + { + return 1; + } + text = (wchar_t*)malloc(len * sizeof(wchar_t) + 8); + text1 = (wchar_t*)malloc(len * sizeof(wchar_t) + 8); + text1_index = 0; + mbstowcs(text, str, len + 1); + switch (trim_flags) + { + case 4: /* trim through */ + for (index = 0; index < len; index++) + { + if (text[index] > 32) + { + text1[text1_index] = text[index]; + text1_index++; + } + } + text1[text1_index] = 0; + break; + case 3: /* trim both */ + got_char = 0; + for (index = 0; index < len; index++) + { + if (got_char) + { + text1[text1_index] = text[index]; + text1_index++; + } + else + { + if (text[index] > 32) + { + text1[text1_index] = text[index]; + text1_index++; + got_char = 1; + } + } + } + text1[text1_index] = 0; + len = text1_index; + /* trim right */ + for (index = len - 1; index >= 0; index--) + { + if (text1[index] > 32) + { + break; + } + } + text1_index = index + 1; + text1[text1_index] = 0; + break; + case 2: /* trim right */ + /* copy it */ + for (index = 0; index < len; index++) + { + text1[text1_index] = text[index]; + text1_index++; + } + /* trim right */ + for (index = len - 1; index >= 0; index--) + { + if (text1[index] > 32) + { + break; + } + } + text1_index = index + 1; + text1[text1_index] = 0; + break; + case 1: /* trim left */ + got_char = 0; + for (index = 0; index < len; index++) + { + if (got_char) + { + text1[text1_index] = text[index]; + text1_index++; + } + else + { + if (text[index] > 32) + { + text1[text1_index] = text[index]; + text1_index++; + got_char = 1; + } + } + } + text1[text1_index] = 0; + break; + } + wcstombs(str, text1, text1_index + 1); + free(text); + free(text1); + return 0; +} + +/*****************************************************************************/ long APP_CC g_load_library(char* in) { diff --git a/common/os_calls.h b/common/os_calls.h index d86776ad..688b52f9 100644 --- a/common/os_calls.h +++ b/common/os_calls.h @@ -161,6 +161,8 @@ int APP_CC g_mbstowcs(twchar* dest, const char* src, int n); int APP_CC g_wcstombs(char* dest, const twchar* src, int n); +int APP_CC +g_strtrim(char* str, int trim_flags); long APP_CC g_load_library(char* in); int APP_CC |