From 7103a0684961a5b19e6ef5502823332b8936a0c2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 5 Dec 2013 20:57:30 +0000 Subject: [PATCH] Swig_offset_string moved to misc.c --- Source/Modules/csharp.cxx | 4 +--- Source/Modules/java.cxx | 4 +--- Source/Modules/lang.cxx | 41 -------------------------------- Source/Swig/misc.c | 49 +++++++++++++++++++++++++++++++++++++++ Source/Swig/swig.h | 1 + 5 files changed, 52 insertions(+), 47 deletions(-) diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 88dbfbad7..9197b4b17 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -18,8 +18,6 @@ /* Hash type used for upcalls from C/C++ */ typedef DOH UpcallData; -// insert N tabs before each new line in s -void Swig_offset_string(String *s, int N); class CSHARP:public Language { static const char *usage; @@ -2004,7 +2002,7 @@ public: } else { for (int i = 0; i < nesting_depth; ++i) Append(old_proxy_class_code, " "); - Append(old_proxy_class_code, "}\n"); + Append(old_proxy_class_code, "}\n\n"); --nesting_depth; } diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index f781f0c39..fdc678dbf 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -18,8 +18,6 @@ /* Hash type used for upcalls from C/C++ */ typedef DOH UpcallData; -// insert N tabs before each new line in s -void Swig_offset_string(String *s, int N); class JAVA:public Language { static const char *usage; @@ -2068,7 +2066,7 @@ public: } else { for (int i = 0; i < nesting_depth; ++i) Append(old_proxy_class_code, " "); - Append(old_proxy_class_code, "}\n"); + Append(old_proxy_class_code, "}\n\n"); --nesting_depth; } diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 5c701bc85..78c37dbb9 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -3632,44 +3632,3 @@ Hash *Language::getClassHash() const { return classhash; } -// insert N tabs before each new line in s -void Swig_offset_string(String *s, int N) -{ - // count a number of lines in s - int lines = 1; - int L = Len(s); - char *start = strchr(Char(s), '\n'); - while (start) { - ++lines; - start = strchr(start + 1, '\n'); - } - // do not count pending new line - if ((Char(s))[L-1] == '\n') - --lines; - // allocate a temporary storage for a padded string - char *res = (char*)malloc(L + lines * N * 2 + 1); - res[L + lines * N * 2] = 0; - - // copy lines to res, prepending tabs to each line - char *p = res; // output pointer - start = Char(s); // start of a current line - char *end = strchr(start, '\n'); // end of a current line - while (end) { - memset(p, ' ', N*2); - p += N*2; - memcpy(p, start, end - start + 1); - p += end - start + 1; - start = end + 1; - end = strchr(start, '\n'); - } - // process the last line - if (*start) { - memset(p, ' ', N*2); - p += N*2; - strcpy(p, start); - } - // replace 's' contents with 'res' - Clear(s); - Append(s, res); - free(res); -} diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index 769882bf8..7d8180d1c 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -1147,6 +1147,55 @@ String *Swig_string_strip(String *s) { return ns; } +/* ----------------------------------------------------------------------------- + * Swig_offset_string() + * + * Insert number tabs before each new line in s + * ----------------------------------------------------------------------------- */ + +void Swig_offset_string(String *s, int number) { + char *res; + char *p; + char *end; + /* count a number of lines in s */ + int lines = 1; + int len = Len(s); + char *start = strchr(Char(s), '\n'); + while (start) { + ++lines; + start = strchr(start + 1, '\n'); + } + /* do not count pending new line */ + if ((Char(s))[len-1] == '\n') + --lines; + /* allocate a temporary storage for a padded string */ + res = (char*)malloc(len + lines * number * 2 + 1); + res[len + lines * number * 2] = 0; + + /* copy lines to res, prepending tabs to each line */ + p = res; /* output pointer */ + start = Char(s); /* start of a current line */ + end = strchr(start, '\n'); /* end of a current line */ + while (end) { + memset(p, ' ', number*2); + p += number*2; + memcpy(p, start, end - start + 1); + p += end - start + 1; + start = end + 1; + end = strchr(start, '\n'); + } + /* process the last line */ + if (*start) { + memset(p, ' ', number*2); + p += number*2; + strcpy(p, start); + } + /* replace 's' contents with 'res' */ + Clear(s); + Append(s, res); + free(res); +} + #ifdef HAVE_PCRE #include diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index 95e3784d9..28a3ba730 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -332,6 +332,7 @@ extern int ParmList_is_compactdefargs(ParmList *p); extern String *Swig_string_lower(String *s); extern String *Swig_string_upper(String *s); extern String *Swig_string_title(String *s); + extern void Swig_offset_string(String *s, int number); extern String *Swig_pcre_version(void); extern void Swig_init(void); extern int Swig_value_wrapper_mode(int mode);