Logo Search packages:      
Sourcecode: sam2p version File versions

SimBuffer::B & SimBuffer::B::appendUnslash ( const Flat other,
int  iniq 
)

Name: Quote::Unslash Input: a double-quoted (backslashed) version of a string without the double quotes themselves Output: the original, unquoted (possibly binary) string Description: Converts a string expressed inside double quotes of some programming language (e.g Ruby, C, Java, Perl, Ruby) to its original, unquoted state. Transformation is done only after backslashes. The following `common' transformations are supported: , , (octal), (alarm bell), (backslash), (escape), (form feed),
(newline), (carriage return), (horizontal tab), (verical tab) , [, (lowercase), (upper case), (skip this), \", \, \... . Compatibility: Ruby, ANSI C, C++, Java (without ....), TCL double quotes (without ....), TCL unquoted strings, Perl5, Pike, AWK, PostScript Level 1, bc, PHP. See also Quote::UnSlashPHPC for full PHP:StripCSlashes() compatibility. See also Quote::UnSlashKnr. Compatible with PHP stripcslashes(). See also Quote::UnSlashKnr. Differs from Quote::UnslashMiddle by not removing the double quotes from string edges. Valid input type: binary Valid input: any binary On invalid input: impossible Inverse of valid: lossy: Quote::NonPathOctal Validity indicator: implemented Output type: any binary Direction: decode Method: gsub Dependencies: -

Parameters:
iniq the char that surrounds the quoted param `other'
other a quoted string
Returns:
an empty string if iniq<256 and param `other' not delimited by iniq

Definition at line 1042 of file gensi.cpp.

References SimBuffer::Flat::beg, SimBuffer::Flat::len, and vi_grow2().

                                                                          {
  slen_t rlen=0;
  slen_t left=other.len;
  register char c; register char const*p=other.beg;
  if (iniq<=256) {
    if (left<2 || *p!=iniq || p[left-1]!=iniq) return*this;
    /* ^^^ return empty string */
    p++; left-=2;
  }
  while (0!=left) { /* Calculate lengths */
    c=*p++;
    if (c!='\\' || left==1) { rlen++; left--; continue; }
    c=*p++;
    if (c>='0' && c<='7') {
      rlen++;
      if (left>=3 && p[0]>='0' && p[0]<='7') {
        if (left>=4 && p[1]>='0' && p[1]<='7') { p+=2; left-=4; }
                                          else { p+=1; left-=3; }
      } else left-=2;
    } else if ((c=='x' || c=='X') && left>=3 && 16!=(hexc2n(p[0]))) {
      rlen++;
      if (left>=4 && 16!=(hexc2n(p[1]))) { p+=2; left-=4; }
                                    else { p+=1; left-=2; }
    } else if ((c=='c' || c=='C') && left>=4 && (p[0]=='-' || p[0]=='[')) {
      rlen++; left-=4; p+=2;
    } else if (c=='l' && left>=3) {
      rlen++; left-=3; p++;
    } else if (c=='u' && left>=3) {
      rlen++; left-=3; p++;
    } else if (c=='\n') {
      left-=2;
    } else { /* backslash is used for escaping a single char */
      rlen++; left-=2;
    }
  }
  
  char *dst; vi_grow2(0, rlen, 0, &dst);
  unsigned tmp1, tmp2;
  left=other.len; p=other.beg;
  if (iniq<=256) {
    assert(!(left<2 || *p!=iniq || p[left-1]!=iniq));
    p++; left-=2;
  }
  while (0!=left) {
    c=*p++;
    if (c!='\\' || left==1) { *dst++=(c); left--; continue; }
    c=*p++;
    if (c>='0' && c<='7') {
      if (left>=3 && p[0]>='0' && p[0]<='7') {
        if (left>=4 && p[1]>='0' && p[1]<='7') {
          *dst++=((char)((c<<6)+(p[0]<<3)+p[1]-'0'*73));
          p+=2; left-=4;
        } else {
          *dst++=((char)((c<<3)+p[0]-'0'*9));
          p+=1; left-=3;
        }
      } else {
        *dst++=((char)(c-'0'));
        left-=2;
      }
    } else if ((c=='x' || c=='X') && left>=3 && 16!=(tmp1=hexc2n(p[0]))) {
      if (left>=4 && 16!=(tmp2=hexc2n(p[1]))) {
        *dst++=((char)((tmp1<<4)+tmp2));
        p+=2; left-=4;
      } else {
        *dst++=((char)tmp1);
        p+=1; left-=2;
      }
    } else if ((c=='c' || c=='C') && left>=4 && (p[0]=='-' || p[0]=='[')) {
      *dst++=((char)(p[1]>='a' && p[1]<='z' ? (p[1]+'A'-'a')^64 : p[1]^64));
      left-=4; p+=2;
    } else if (c=='l' && left>=3) {
      *dst++=((char)(p[0]>='A' && p[0]<='Z' ? p[0]+'a'-'A' : p[0]));
      left-=3; p++;
    } else if (c=='u' && left>=3) {
      *dst++=((char)(p[0]>='a' && p[0]<='z' ? p[0]+'A'-'a' : p[0]));
      left-=3; p++;
    } else if (c=='\n') {
      left-=2;
    } else { /* backslash is used for escaping a single char */
           if (c=='a') c=007; // \x07 (alarm bell)
      else if (c=='b') c=010; // \x08 (backspace) (_not_ alarm bell)
      else if (c=='e') c=033; // \x1B (escape)
      else if (c=='f') c=014; // \x0C (form feed)
      else if (c=='n') c=012; // \x0A (newline, line feed)
      else if (c=='r') c=015; // \x0D (carriage return)
      else if (c=='t') c=011; // \x09 (horizontal tab)
      else if (c=='v') c=013; // \x0B (vertical tab)
      *dst++=(c); left-=2;
      // if (0!=left--) { *dst++=(*p++); left--; } /* already escaped 1 */
    }
  }
  return*this;  
}


Generated by  Doxygen 1.6.0   Back to index