diff --git a/Compiler/runtime/systemimpl.c b/Compiler/runtime/systemimpl.c index 6b31fee3aae..0dd89c9f3ae 100644 --- a/Compiler/runtime/systemimpl.c +++ b/Compiler/runtime/systemimpl.c @@ -161,6 +161,37 @@ static int set_ldflags(char *str) return 0; } +RML_BEGIN_LABEL(System__trimChar) +{ + char* str = RML_STRINGDATA(rmlA0); + char char_to_be_trimmed = (char)RML_STRINGDATA(rmlA1)[0]; + int length=strlen(str); + int start_pos = 0; + int end_pos = length - 1; + char* res; + while(start_pos < end_pos){ + if(str[start_pos] == char_to_be_trimmed) + start_pos++; + if(str[end_pos] == char_to_be_trimmed) + end_pos--; + if(str[start_pos] != char_to_be_trimmed && str[end_pos] != char_to_be_trimmed) + break; + } + if(end_pos > start_pos){ + res= (char*)malloc(end_pos - start_pos +2); + strncpy(res,&str[start_pos],end_pos - start_pos+1); + res[end_pos - start_pos+1] = '\0'; + rmlA0 = (void*) mk_scon(res); + free(res); + RML_TAILCALLK(rmlSC); + + }else{ + rmlA0 = (void*) mk_scon(""); + RML_TAILCALLK(rmlSC); + } +} +RML_END_LABEL + // windows and mingw32 #if defined(__MINGW32__) || defined(_MSC_VER) @@ -450,38 +481,6 @@ RML_BEGIN_LABEL(System__trim) } RML_END_LABEL -RML_BEGIN_LABEL(System__trimChar) -{ - char* str = RML_STRINGDATA(rmlA0); - char char_to_be_trimmed = (char)RML_STRINGDATA(rmlA1)[0]; - int length=strlen(str); - int start_pos = 0; - int end_pos = length - 1; - char* res; - while(start_pos < end_pos){ - if(str[start_pos] == char_to_be_trimmed) - start_pos++; - if(str[end_pos] == char_to_be_trimmed) - end_pos--; - if(str[start_pos] != char_to_be_trimmed && str[end_pos] != char_to_be_trimmed) - break; - } - if(end_pos > start_pos){ - res= (char*)malloc(end_pos - start_pos +1); - strncpy(res,&str[start_pos],end_pos - start_pos); - res[end_pos - start_pos] = '\0'; - rmlA0 = (void*) mk_scon(res); - free(res); - RML_TAILCALLK(rmlSC); - - }else{ - rmlA0 = (void*) mk_scon(""); - RML_TAILCALLK(rmlSC); - } -} -RML_END_LABEL - - RML_BEGIN_LABEL(System__strcmp) { @@ -2217,38 +2216,6 @@ RML_BEGIN_LABEL(System__trim) } RML_END_LABEL -RML_BEGIN_LABEL(System__trimChar) -{ - char* str = RML_STRINGDATA(rmlA0); - char char_to_be_trimmed = (char)RML_STRINGDATA(rmlA1)[0]; - int length=strlen(str); - int start_pos = 0; - int end_pos = length - 1; - char* res; - while(start_pos < end_pos){ - if(str[start_pos] == char_to_be_trimmed) - start_pos++; - if(str[end_pos] == char_to_be_trimmed) - end_pos--; - if(str[start_pos] != char_to_be_trimmed && str[end_pos] != char_to_be_trimmed) - break; - } - if(end_pos > start_pos){ - res= (char*)malloc(end_pos - start_pos +1); - strncpy(res,&str[start_pos],end_pos - start_pos); - res[end_pos - start_pos] = '\0'; - rmlA0 = (void*) mk_scon(res); - free(res); - RML_TAILCALLK(rmlSC); - - }else{ - rmlA0 = (void*) mk_scon(""); - RML_TAILCALLK(rmlSC); - } -} -RML_END_LABEL - - RML_BEGIN_LABEL(System__strcmp) { char *str = RML_STRINGDATA(rmlA0);