15a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes/* 25a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * Copyright (C) 2008 The Android Open Source Project 35a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * All rights reserved. 45a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * 55a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * Redistribution and use in source and binary forms, with or without 65a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * modification, are permitted provided that the following conditions 75a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * are met: 85a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * * Redistributions of source code must retain the above copyright 95a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * notice, this list of conditions and the following disclaimer. 105a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * * Redistributions in binary form must reproduce the above copyright 115a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * notice, this list of conditions and the following disclaimer in 125a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * the documentation and/or other materials provided with the 135a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * distribution. 145a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * 155a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 165a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 175a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 185a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 195a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 205a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 215a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 225a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 235a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 245a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 255a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 265a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes * SUCH DAMAGE. 275a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes */ 285a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes 295a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes#include <ctype.h> 305a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes#include <stdlib.h> 315a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes#include <string.h> 325a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes#include <wchar.h> 33dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albert#include <wctype.h> 345a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes 35c42f5c6fe6f52c9a7082d2a43d0af42326a9c6d1Elliott Hughes// TODO: these only work for the ASCII range; rewrite to dlsym icu4c? http://b/14499654 365a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes 375a0aa3dee247a313f04252cf45608097695d5953Elliott Hughesint iswalnum(wint_t wc) { return isalnum(wc); } 385a0aa3dee247a313f04252cf45608097695d5953Elliott Hughesint iswalpha(wint_t wc) { return isalpha(wc); } 395a0aa3dee247a313f04252cf45608097695d5953Elliott Hughesint iswblank(wint_t wc) { return isblank(wc); } 405a0aa3dee247a313f04252cf45608097695d5953Elliott Hughesint iswcntrl(wint_t wc) { return iscntrl(wc); } 415a0aa3dee247a313f04252cf45608097695d5953Elliott Hughesint iswdigit(wint_t wc) { return isdigit(wc); } 425a0aa3dee247a313f04252cf45608097695d5953Elliott Hughesint iswgraph(wint_t wc) { return isgraph(wc); } 435a0aa3dee247a313f04252cf45608097695d5953Elliott Hughesint iswlower(wint_t wc) { return islower(wc); } 445a0aa3dee247a313f04252cf45608097695d5953Elliott Hughesint iswprint(wint_t wc) { return isprint(wc); } 455a0aa3dee247a313f04252cf45608097695d5953Elliott Hughesint iswpunct(wint_t wc) { return ispunct(wc); } 465a0aa3dee247a313f04252cf45608097695d5953Elliott Hughesint iswspace(wint_t wc) { return isspace(wc); } 475a0aa3dee247a313f04252cf45608097695d5953Elliott Hughesint iswupper(wint_t wc) { return isupper(wc); } 485a0aa3dee247a313f04252cf45608097695d5953Elliott Hughesint iswxdigit(wint_t wc) { return isxdigit(wc); } 495a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes 50dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albertint iswalnum_l(wint_t c, locale_t) { return iswalnum(c); } 51dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albertint iswalpha_l(wint_t c, locale_t) { return iswalpha(c); } 52dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albertint iswblank_l(wint_t c, locale_t) { return iswblank(c); } 53dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albertint iswcntrl_l(wint_t c, locale_t) { return iswcntrl(c); } 54dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albertint iswdigit_l(wint_t c, locale_t) { return iswdigit(c); } 55dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albertint iswgraph_l(wint_t c, locale_t) { return iswgraph(c); } 56dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albertint iswlower_l(wint_t c, locale_t) { return iswlower(c); } 57dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albertint iswprint_l(wint_t c, locale_t) { return iswprint(c); } 58dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albertint iswpunct_l(wint_t c, locale_t) { return iswpunct(c); } 59dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albertint iswspace_l(wint_t c, locale_t) { return iswspace(c); } 60dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albertint iswupper_l(wint_t c, locale_t) { return iswupper(c); } 61dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albertint iswxdigit_l(wint_t c, locale_t) { return iswxdigit(c); } 62dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albert 635a0aa3dee247a313f04252cf45608097695d5953Elliott Hughesint iswctype(wint_t wc, wctype_t char_class) { 645a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes switch (char_class) { 65c42f5c6fe6f52c9a7082d2a43d0af42326a9c6d1Elliott Hughes case WC_TYPE_ALNUM: return iswalnum(wc); 66c42f5c6fe6f52c9a7082d2a43d0af42326a9c6d1Elliott Hughes case WC_TYPE_ALPHA: return iswalpha(wc); 67c42f5c6fe6f52c9a7082d2a43d0af42326a9c6d1Elliott Hughes case WC_TYPE_BLANK: return iswblank(wc); 68c42f5c6fe6f52c9a7082d2a43d0af42326a9c6d1Elliott Hughes case WC_TYPE_CNTRL: return iswcntrl(wc); 69c42f5c6fe6f52c9a7082d2a43d0af42326a9c6d1Elliott Hughes case WC_TYPE_DIGIT: return iswdigit(wc); 70c42f5c6fe6f52c9a7082d2a43d0af42326a9c6d1Elliott Hughes case WC_TYPE_GRAPH: return iswgraph(wc); 71c42f5c6fe6f52c9a7082d2a43d0af42326a9c6d1Elliott Hughes case WC_TYPE_LOWER: return iswlower(wc); 72c42f5c6fe6f52c9a7082d2a43d0af42326a9c6d1Elliott Hughes case WC_TYPE_PRINT: return iswprint(wc); 73c42f5c6fe6f52c9a7082d2a43d0af42326a9c6d1Elliott Hughes case WC_TYPE_PUNCT: return iswpunct(wc); 74c42f5c6fe6f52c9a7082d2a43d0af42326a9c6d1Elliott Hughes case WC_TYPE_SPACE: return iswspace(wc); 75c42f5c6fe6f52c9a7082d2a43d0af42326a9c6d1Elliott Hughes case WC_TYPE_UPPER: return iswupper(wc); 76c42f5c6fe6f52c9a7082d2a43d0af42326a9c6d1Elliott Hughes case WC_TYPE_XDIGIT: return iswxdigit(wc); 775a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes default: return 0; 785a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes } 795a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes} 805a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes 81dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albertint iswctype_l(wint_t wc, wctype_t char_class, locale_t) { 82dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albert return iswctype(wc, char_class); 83dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albert} 84dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albert 855a0aa3dee247a313f04252cf45608097695d5953Elliott Hugheswint_t towlower(wint_t wc) { return tolower(wc); } 865a0aa3dee247a313f04252cf45608097695d5953Elliott Hugheswint_t towupper(wint_t wc) { return toupper(wc); } 875a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes 88dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albertint towupper_l(int c, locale_t) { return towupper(c); } 89dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albertint towlower_l(int c, locale_t) { return towlower(c); } 90dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albert 915a0aa3dee247a313f04252cf45608097695d5953Elliott Hugheswctype_t wctype(const char* property) { 925a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes static const char* const properties[WC_TYPE_MAX] = { 935a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes "<invalid>", 945a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes "alnum", "alpha", "blank", "cntrl", "digit", "graph", 955a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes "lower", "print", "punct", "space", "upper", "xdigit" 965a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes }; 975a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes for (size_t i = 0; i < WC_TYPE_MAX; ++i) { 985a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes if (!strcmp(properties[i], property)) { 995a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes return static_cast<wctype_t>(i); 1005a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes } 1015a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes } 1025a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes return static_cast<wctype_t>(0); 1035a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes} 1045a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes 105dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albertwctype_t wctype_l(const char* property, locale_t) { 106dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albert return wctype(property); 107dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albert} 108dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668Dan Albert 1095a0aa3dee247a313f04252cf45608097695d5953Elliott Hughesint wcwidth(wchar_t wc) { 1105a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes return (wc > 0); 1115a0aa3dee247a313f04252cf45608097695d5953Elliott Hughes} 112