diff --git a/src/common/unicode.cpp b/src/common/unicode.cpp new file mode 100644 index 00000000..5ee37122 --- /dev/null +++ b/src/common/unicode.cpp @@ -0,0 +1,72 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2015 - 2016, Paul Beckingham, Federico Hernandez. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include + +//////////////////////////////////////////////////////////////////////////////// +// Complete Unicode whitespace list. +// +// http://en.wikipedia.org/wiki/Whitespace_character +// Updated 2015-09-13 +// Static +// +// TODO This list should be derived from the Unicode database. +bool unicodeWhitespace (int c) +{ + return (c == 0x0020 || // space Common Separator, space + c == 0x0009 || // Common Other, control HT, Horizontal Tab + c == 0x000A || // Common Other, control LF, Line feed + c == 0x000B || // Common Other, control VT, Vertical Tab + c == 0x000C || // Common Other, control FF, Form feed + c == 0x000D || // Common Other, control CR, Carriage return + c == 0x0085 || // Common Other, control NEL, Next line + c == 0x00A0 || // no-break space Common Separator, space + c == 0x1680 || // ogham space mark Ogham Separator, space + c == 0x180E || // mongolian vowel separator Mongolian Separator, space + c == 0x2000 || // en quad Common Separator, space + c == 0x2001 || // em quad Common Separator, space + c == 0x2002 || // en space Common Separator, space + c == 0x2003 || // em space Common Separator, space + c == 0x2004 || // three-per-em space Common Separator, space + c == 0x2005 || // four-per-em space Common Separator, space + c == 0x2006 || // six-per-em space Common Separator, space + c == 0x2007 || // figure space Common Separator, space + c == 0x2008 || // punctuation space Common Separator, space + c == 0x2009 || // thin space Common Separator, space + c == 0x200A || // hair space Common Separator, space + c == 0x200B || // zero width space + c == 0x200C || // zero width non-joiner + c == 0x200D || // zero width joiner + c == 0x2028 || // line separator Common Separator, line + c == 0x2029 || // paragraph separator Common Separator, paragraph + c == 0x202F || // narrow no-break space Common Separator, space + c == 0x205F || // medium mathematical space Common Separator, space + c == 0x2060 || // word joiner + c == 0x3000); // ideographic space Common Separator, space +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/common/unicode.h b/src/common/unicode.h new file mode 100644 index 00000000..ea26f659 --- /dev/null +++ b/src/common/unicode.h @@ -0,0 +1,33 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2015 - 2016, Paul Beckingham, Federico Hernandez. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_UNICODE +#define INCLUDED_UNICODE + +bool unicodeWhitespace (unsigned int); + +#endif +////////////////////////////////////////////////////////////////////////////////