Skip to content

Commit

Permalink
-Fixed bug (really fixed this time ;) on trimChar. Moved it to platfo…
Browse files Browse the repository at this point in the history
…rm independent impl. first in file.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@4753 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Jan 8, 2010
1 parent 8b25b38 commit 9014d4f
Showing 1 changed file with 31 additions and 64 deletions.
95 changes: 31 additions & 64 deletions Compiler/runtime/systemimpl.c
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9014d4f

Please sign in to comment.