Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / Source Help

Trim function

A community discussion post from the original code:zIRON forum.

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

Trim function

here is the original code from bcx

function Trim (char* str)
{  
  while(*S==32 || *S==9 || *S==10 || *S==11 || *S==13)
    S++;     
  register int i = strlen(S);
  while( i>0 && (S[i-1]==32 || S[i-1]==9 || S[i-1]==10
             || S[i-1]==11 || S[i-1]==13))
    i--;
  char *strtmp=BCX_TmpStr(i);
  return (char*)memcpy(strtmp,S,i);  
}

so i start trying to convert it like this

function Trim (char* str)
{  
//  while(*S==32 || *S==9 || *S==10 || *S==11 || *S==13)
//    S++;
  Ebx = str;
  al = char[Ebx];
  while(al == 32 or al == 9 or al == 10 or al == 11 or al == 13) // error here
   {
     Ebx++;
     al = char[Ebx];
   }  
}

but it did not compiled any help please.

http://www.freewebs.com/ogremagic/index.htm

Replies

Colin admin
Posts
928
Threads
49
Location
Bulgaria

note that ors and ands must be parenthesized

while((al == 32) or (al == 9) or (al == 10) or (al == 11) or (al == 13))
Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

after made your notes still have this error

Expected ) but found or ?

http://www.freewebs.com/ogremagic/index.htm

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

any way i have solved it by this code , BTW if statement seems it support multi or without parenthesis.

/*
  while((al == 32) or (al == 9) or (al == 10) or (al == 11) or (al == 13))
   {
     Ebx++;
     al = char[Ebx];
   }
*/

@Rept:     
 if(al==32 or al==9 or al==10 or al==11 or al==13)
  { 
    Ebx++;
    al = char[Ebx];
    goto @Rept;
  }   

http://www.freewebs.com/ogremagic/index.htm

Colin admin
Posts
928
Threads
49
Location
Bulgaria

i will take a look into that thanks

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

ok here is the function

function Trim (char* str)
{  
  uses Ebx Ecx;
  Ebx = str;
  al = char[Ebx];
@Rept:     
 if(al==32 or al==9 or al==10 or al==11 or al==13)
  { 
    Ebx++;
    al = char[Ebx];
    goto @Rept;
  }     
 Ecx = Ebx;
 while(char[Ecx] != 0)
  {
     Ecx++;
  }
 sub Ecx,Ebx 
 Eax = GetTmpStr(Ecx);
 push Eax
 strlcpy(Eax,Ebx,Ecx);
 pop Eax
}

http://www.freewebs.com/ogremagic/index.htm

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

i have changed Trim so that you can supply a pointer to holed the length of trimed string.

but when i used the indirect pointer just like C&C++ Ziron didnot accept it.

any help please?

function Trim(char* str;int32* len)
{  
  uses Ebx Ecx;
  Ebx = str;
  al = char[Ebx];
@Rept:     
 if(al==32 or al==9 or al==10 or al==11 or al==13)
  { 
    Ebx++;
    al = char[Ebx];
    goto @Rept;
  }     
 Ecx = Ebx;
 while(char[Ecx] != 0)
  {
     Ecx++;
  }
 al = char[Ecx-1];
@Rept1:
  if(al==32 or al==9 or al==10 or al==11 or al==13)
  { 
    Ecx--;
    al = char[Ecx-1];
    goto @Rept1;
  }     
 sub Ecx,Ebx 
 if(len != nil )
  {
    *len = Ecx;  //-------------------- error here
  }
 Eax = GetTmpStr(Ecx);
 push Eax
 strlcpy(Eax,Ebx,Ecx);
 pop Eax
 char[Eax+Ecx]=0;
}

http://www.freewebs.com/ogremagic/index.htm

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

sorry i pushed '' instead # , and have on way to change previous post.

http://www.freewebs.com/ogremagic/index.htm