Logo Search packages:      
Sourcecode: rapple version File versions  Download package

static void rpl_parse_escape_amperands ( rpl_str_t *  input  )  [static]

Escapes ampersands by replacing instances of & with &

Parameters:
src 
Returns:
the contents of the string src with characters matching entity keys replaced with entity literals.

Definition at line 308 of file parser.c.

References rpl_me_free(), and rpl_me_malloc().

Referenced by rpl_parse().

{
    rpl_str_t src, sp, cp, dest;
    int amp_count = 0;
    size_t s_length, l_length, i, j=0;
      static rpl_c_str_t amp = "&";

    assert(*input != NULL);

      /* calculate the length of the return string */
      src = *input;
    s_length = strlen(src);
      sp = src;
      while((cp = strchr(sp,'&')) != NULL)
      {
            amp_count++;
            sp = cp + 1;
      }

      /* now search and replace ampersands if necessary */
      if(amp_count > 0)
      {
      dest = (rpl_str_t)rpl_me_malloc(s_length + strlen(amp) * amp_count + 1);
            for(i=0; i<s_length; i++) {
                  /* is the current character an entity that requires replacement ? */
                  if(src[i] == '&')
                  {
                        /* match! replace entity with literal form */
                        l_length = strlen(amp);
                        snprintf(dest+j, l_length + 1, "%s", amp);
                        j += l_length;
                  } else {
                        /* no match here, move along please */
                        dest[j++] = src[i];
                  }
            }
            dest[j] = '\0';
            *input = dest;
            rpl_me_free(src);
      } 
}


Generated by  Doxygen 1.6.0   Back to index