diff options
author | Bruno Haible <bruno@clisp.org> | 2003-04-04 10:04:24 +0000 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2003-04-04 10:04:24 +0000 |
commit | ec3d1127fa7742bd291bfe039fd76b4d2381da6f (patch) | |
tree | 00b6e3fcb77aa8b2e9fa88676daa78fddd07345a /src/positions.cc | |
parent | 68f03b3ea7cd6b2df10d395caf52652da7ca0df6 (diff) | |
download | gperf-ec3d1127fa7742bd291bfe039fd76b4d2381da6f.tar.gz |
Change the positions to be 0-based, instead of 1-based.
Diffstat (limited to 'src/positions.cc')
-rw-r--r-- | src/positions.cc | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/positions.cc b/src/positions.cc index f02ff67..2a096c1 100644 --- a/src/positions.cc +++ b/src/positions.cc @@ -35,7 +35,7 @@ bool Positions::contains (int pos) const { unsigned int count = _size; - const unsigned char *p = _positions + _size - 1; + const int *p = _positions + _size - 1; for (; count > 0; p--, count--) { @@ -52,13 +52,13 @@ Positions::add (int pos) { unsigned int count = _size; - if (count == MAX_KEY_POS + 1) + if (count == MAX_SIZE) { fprintf (stderr, "Positions::add internal error: overflow\n"); exit (1); } - unsigned char *p = _positions + _size - 1; + int *p = _positions + _size - 1; for (; count > 0; p--, count--) { @@ -81,7 +81,7 @@ Positions::remove (int pos) unsigned int count = _size; if (count > 0) { - unsigned char *p = _positions + _size - 1; + int *p = _positions + _size - 1; if (*p == pos) { @@ -90,7 +90,7 @@ Positions::remove (int pos) } if (*p < pos) { - unsigned char prev = *p; + int prev = *p; for (;;) { @@ -106,7 +106,7 @@ Positions::remove (int pos) } if (*p > pos) break; - unsigned char curr = *p; + int curr = *p; *p = prev; prev = curr; } @@ -123,17 +123,18 @@ Positions::print () const bool first = true; bool seen_LASTCHAR = false; unsigned int count = _size; - const unsigned char *p = _positions + _size - 1; + const int *p = _positions + _size - 1; - for (; count > 0; p--, count--) + for (; count > 0; p--) { + count--; if (*p == LASTCHAR) seen_LASTCHAR = true; else { if (!first) printf (","); - printf ("%d", *p); + printf ("%d", *p + 1); if (count > 0 && p[-1] == *p + 1) { printf ("-"); @@ -143,7 +144,7 @@ Positions::print () const count--; } while (count > 0 && p[-1] == *p + 1); - printf ("%d", *p); + printf ("%d", *p + 1); } first = false; } |