-
Nadav Har'El authored
Fixes #314. In two's complement, the lowest signed 8-bit number is -128, not -127. By wrongly starting to generate the ctype array starting with -127 instead of -128, we got all the locale ctype questions shifted by one character; For example character 32 (' ') was not considered a space, but 31 was! We didn't see this bug because our C library isspace() and friends are currently implemented without using the locale framework (which is fine, as we only support the "C" locale anyway). However, this bug is apparent in C++, as explained in issue #314: std::isspace() returns the wrong answer, and C++ facilities which use this under the hood - such as reading from an istream which is supposed to stop at a space - also got broken. Signed-off-by:
Nadav Har'El <nyh@cloudius-systems.com> Signed-off-by:
Pekka Enberg <penberg@cloudius-systems.com>
Nadav Har'El authoredFixes #314. In two's complement, the lowest signed 8-bit number is -128, not -127. By wrongly starting to generate the ctype array starting with -127 instead of -128, we got all the locale ctype questions shifted by one character; For example character 32 (' ') was not considered a space, but 31 was! We didn't see this bug because our C library isspace() and friends are currently implemented without using the locale framework (which is fine, as we only support the "C" locale anyway). However, this bug is apparent in C++, as explained in issue #314: std::isspace() returns the wrong answer, and C++ facilities which use this under the hood - such as reading from an istream which is supposed to stop at a space - also got broken. Signed-off-by:
Nadav Har'El <nyh@cloudius-systems.com> Signed-off-by:
Pekka Enberg <penberg@cloudius-systems.com>
gen-ctype-data.cc 723 B
/*
* Copyright (C) 2013 Cloudius Systems, Ltd.
*
* This work is open source software, licensed under the terms of the
* BSD license as described in the LICENSE file in the top-level directory.
*/
#include <iostream>
#include <ctype.h>
namespace {
void do_ctype(std::ostream& os, int i, int (*f)(int), std::string name)
{
if (f(i)) {
os << " | " << name;
}
}
}
#define DO(x) do_ctype(std::cout, i, is##x, "_IS" #x)
int main(int ac, char **av)
{
for (int i = -128; i < 256; ++i) {
std::cout << "0";
DO(alnum);
DO(alpha);
/* DO(ascii); */
DO(blank);
DO(cntrl);
DO(digit);
DO(graph);
DO(lower);
DO(print);
DO(punct);
DO(space);
DO(upper);
DO(xdigit);
std::cout << ",\n";
}
}