summaryrefslogtreecommitdiffstats
path: root/common/os_calls.c
diff options
context:
space:
mode:
authorjsorg71 <jsorg71>2007-10-27 05:53:19 +0000
committerjsorg71 <jsorg71>2007-10-27 05:53:19 +0000
commitd3fa8fd6f6cefaf61898af30655124b921602318 (patch)
tree54da10054fff3edf1dacdc55bc390090637dca0c /common/os_calls.c
parentca37e8cb1d0c697a2b0b63afe9101a570ba2fb2a (diff)
downloadxrdp-proprietary-d3fa8fd6f6cefaf61898af30655124b921602318.tar.gz
xrdp-proprietary-d3fa8fd6f6cefaf61898af30655124b921602318.zip
added g_strtrim
Diffstat (limited to 'common/os_calls.c')
-rw-r--r--common/os_calls.c119
1 files changed, 119 insertions, 0 deletions
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)
{