File: percent.c

package info (click to toggle)
publicfile 0.52-13
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 896 kB
  • sloc: ansic: 3,903; makefile: 468; sh: 296
file content (35 lines) | stat: -rw-r--r-- 566 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "percent.h"

static unsigned char fromhex(unsigned char t)
{
  unsigned char u;

  u = t - 'a';
  if (u < 6) return u + 10;
  u = t - 'A';
  if (u < 6) return u + 10;
  u = t - '0';
  if (u < 10) return u;
  return 0;
}

void percent(stralloc *sa)
{
  int i;
  int j;
  char ch;

  i = j = 0;
  for (;;) {
    if (j >= sa->len) break;
    ch = sa->s[j++];
    if (ch == '%') {
      if (j >= sa->len) break;
      ch = 16 * fromhex(sa->s[j++]);
      if (j >= sa->len) break;
      ch += fromhex(sa->s[j++]);
    }
    sa->s[i++] = ch;
  }
  sa->len = i;
}