📄 icu.cpp
字号:
/*
*
* Copyright (c) 2004
* John Maddock
*
* Use, modification and distribution are subject to the
* Boost Software License, Version 1.0. (See accompanying file
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE icu.cpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Unicode regular expressions on top of the ICU Library.
*/
#define BOOST_REGEX_SOURCE
#include <boost/regex/config.hpp>
#ifdef BOOST_HAS_ICU
#define BOOST_REGEX_ICU_INSTANTIATE
#include <boost/regex/icu.hpp>
namespace boost{
namespace re_detail{
icu_regex_traits_implementation::string_type icu_regex_traits_implementation::do_transform(const char_type* p1, const char_type* p2, const U_NAMESPACE_QUALIFIER Collator* pcoll) const
{
// TODO make thread safe!!!! :
typedef u32_to_u16_iterator<const char_type*, ::UChar> itt;
itt i(p1), j(p2);
#ifndef BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS
std::vector< ::UChar> t(i, j);
#else
std::vector< ::UChar> t;
while(i != j)
t.push_back(*i++);
#endif
::uint8_t result[100];
::int32_t len;
if(t.size())
len = pcoll->getSortKey(&*t.begin(), static_cast< ::int32_t>(t.size()), result, sizeof(result));
else
len = pcoll->getSortKey(static_cast<UChar const*>(0), static_cast< ::int32_t>(0), result, sizeof(result));
if(std::size_t(len) > sizeof(result))
{
scoped_array< ::uint8_t> presult(new ::uint8_t[len+1]);
if(t.size())
len = pcoll->getSortKey(&*t.begin(), static_cast< ::int32_t>(t.size()), presult.get(), len+1);
else
len = pcoll->getSortKey(static_cast<UChar const*>(0), static_cast< ::int32_t>(0), presult.get(), len+1);
if((0 == presult[len-1]) && (len > 1))
--len;
#ifndef BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS
return string_type(presult.get(), presult.get()+len);
#else
string_type sresult;
::uint8_t const* ia = presult.get();
::uint8_t const* ib = presult.get()+len;
while(ia != ib)
sresult.push_back(*ia++);
return sresult;
#endif
}
if((0 == result[len-1]) && (len > 1))
--len;
#ifndef BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS
return string_type(result, result+len);
#else
string_type sresult;
::uint8_t const* ia = result;
::uint8_t const* ib = result+len;
while(ia != ib)
sresult.push_back(*ia++);
return sresult;
#endif
}
}
icu_regex_traits::size_type icu_regex_traits::length(const char_type* p)
{
size_type result = 0;
while(*p)
{
++p;
++result;
}
return result;
}
//
// define our bitmasks:
//
const icu_regex_traits::char_class_type icu_regex_traits::mask_blank = icu_regex_traits::char_class_type(1) << offset_blank;
const icu_regex_traits::char_class_type icu_regex_traits::mask_space = icu_regex_traits::char_class_type(1) << offset_space;
const icu_regex_traits::char_class_type icu_regex_traits::mask_xdigit = icu_regex_traits::char_class_type(1) << offset_xdigit;
const icu_regex_traits::char_class_type icu_regex_traits::mask_underscore = icu_regex_traits::char_class_type(1) << offset_underscore;
const icu_regex_traits::char_class_type icu_regex_traits::mask_unicode = icu_regex_traits::char_class_type(1) << offset_unicode;
const icu_regex_traits::char_class_type icu_regex_traits::mask_any = icu_regex_traits::char_class_type(1) << offset_any;
const icu_regex_traits::char_class_type icu_regex_traits::mask_ascii = icu_regex_traits::char_class_type(1) << offset_ascii;
icu_regex_traits::char_class_type icu_regex_traits::lookup_icu_mask(const ::UChar32* p1, const ::UChar32* p2)
{
static const ::UChar32 prop_name_table[] = {
/* any */ 'a', 'n', 'y',
/* ascii */ 'a', 's', 'c', 'i', 'i',
/* assigned */ 'a', 's', 's', 'i', 'g', 'n', 'e', 'd',
/* c* */ 'c', '*',
/* cc */ 'c', 'c',
/* cf */ 'c', 'f',
/* closepunctuation */ 'c', 'l', 'o', 's', 'e', 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
/* cn */ 'c', 'n',
/* co */ 'c', 'o',
/* connectorpunctuation */ 'c', 'o', 'n', 'n', 'e', 'c', 't', 'o', 'r', 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
/* control */ 'c', 'o', 'n', 't', 'r', 'o', 'l',
/* cs */ 'c', 's',
/* currencysymbol */ 'c', 'u', 'r', 'r', 'e', 'n', 'c', 'y', 's', 'y', 'm', 'b', 'o', 'l',
/* dashpunctuation */ 'd', 'a', 's', 'h', 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
/* decimaldigitnumber */ 'd', 'e', 'c', 'i', 'm', 'a', 'l', 'd', 'i', 'g', 'i', 't', 'n', 'u', 'm', 'b', 'e', 'r',
/* enclosingmark */ 'e', 'n', 'c', 'l', 'o', 's', 'i', 'n', 'g', 'm', 'a', 'r', 'k',
/* finalpunctuation */ 'f', 'i', 'n', 'a', 'l', 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
/* format */ 'f', 'o', 'r', 'm', 'a', 't',
/* initialpunctuation */ 'i', 'n', 'i', 't', 'i', 'a', 'l', 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
/* l* */ 'l', '*',
/* letter */ 'l', 'e', 't', 't', 'e', 'r',
/* letternumber */ 'l', 'e', 't', 't', 'e', 'r', 'n', 'u', 'm', 'b', 'e', 'r',
/* lineseparator */ 'l', 'i', 'n', 'e', 's', 'e', 'p', 'a', 'r', 'a', 't', 'o', 'r',
/* ll */ 'l', 'l',
/* lm */ 'l', 'm',
/* lo */ 'l', 'o',
/* lowercaseletter */ 'l', 'o', 'w', 'e', 'r', 'c', 'a', 's', 'e', 'l', 'e', 't', 't', 'e', 'r',
/* lt */ 'l', 't',
/* lu */ 'l', 'u',
/* m* */ 'm', '*',
/* mark */ 'm', 'a', 'r', 'k',
/* mathsymbol */ 'm', 'a', 't', 'h', 's', 'y', 'm', 'b', 'o', 'l',
/* mc */ 'm', 'c',
/* me */ 'm', 'e',
/* mn */ 'm', 'n',
/* modifierletter */ 'm', 'o', 'd', 'i', 'f', 'i', 'e', 'r', 'l', 'e', 't', 't', 'e', 'r',
/* modifiersymbol */ 'm', 'o', 'd', 'i', 'f', 'i', 'e', 'r', 's', 'y', 'm', 'b', 'o', 'l',
/* n* */ 'n', '*',
/* nd */ 'n', 'd',
/* nl */ 'n', 'l',
/* no */ 'n', 'o',
/* nonspacingmark */ 'n', 'o', 'n', 's', 'p', 'a', 'c', 'i', 'n', 'g', 'm', 'a', 'r', 'k',
/* notassigned */ 'n', 'o', 't', 'a', 's', 's', 'i', 'g', 'n', 'e', 'd',
/* number */ 'n', 'u', 'm', 'b', 'e', 'r',
/* openpunctuation */ 'o', 'p', 'e', 'n', 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
/* other */ 'o', 't', 'h', 'e', 'r',
/* otherletter */ 'o', 't', 'h', 'e', 'r', 'l', 'e', 't', 't', 'e', 'r',
/* othernumber */ 'o', 't', 'h', 'e', 'r', 'n', 'u', 'm', 'b', 'e', 'r',
/* otherpunctuation */ 'o', 't', 'h', 'e', 'r', 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
/* othersymbol */ 'o', 't', 'h', 'e', 'r', 's', 'y', 'm', 'b', 'o', 'l',
/* p* */ 'p', '*',
/* paragraphseparator */ 'p', 'a', 'r', 'a', 'g', 'r', 'a', 'p', 'h', 's', 'e', 'p', 'a', 'r', 'a', 't', 'o', 'r',
/* pc */ 'p', 'c',
/* pd */ 'p', 'd',
/* pe */ 'p', 'e',
/* pf */ 'p', 'f',
/* pi */ 'p', 'i',
/* po */ 'p', 'o',
/* privateuse */ 'p', 'r', 'i', 'v', 'a', 't', 'e', 'u', 's', 'e',
/* ps */ 'p', 's',
/* punctuation */ 'p', 'u', 'n', 'c', 't', 'u', 'a', 't', 'i', 'o', 'n',
/* s* */ 's', '*',
/* sc */ 's', 'c',
/* separator */ 's', 'e', 'p', 'a', 'r', 'a', 't', 'o', 'r',
/* sk */ 's', 'k',
/* sm */ 's', 'm',
/* so */ 's', 'o',
/* spaceseparator */ 's', 'p', 'a', 'c', 'e', 's', 'e', 'p', 'a', 'r', 'a', 't', 'o', 'r',
/* spacingcombiningmark */ 's', 'p', 'a', 'c', 'i', 'n', 'g', 'c', 'o', 'm', 'b', 'i', 'n', 'i', 'n', 'g', 'm', 'a', 'r', 'k',
/* surrogate */ 's', 'u', 'r', 'r', 'o', 'g', 'a', 't', 'e',
/* symbol */ 's', 'y', 'm', 'b', 'o', 'l',
/* titlecase */ 't', 'i', 't', 'l', 'e', 'c', 'a', 's', 'e',
/* titlecaseletter */ 't', 'i', 't', 'l', 'e', 'c', 'a', 's', 'e', 'l', 'e', 't', 't', 'e', 'r',
/* uppercaseletter */ 'u', 'p', 'p', 'e', 'r', 'c', 'a', 's', 'e', 'l', 'e', 't', 't', 'e', 'r',
/* z* */ 'z', '*',
/* zl */ 'z', 'l',
/* zp */ 'z', 'p',
/* zs */ 'z', 's',
};
static const re_detail::character_pointer_range< ::UChar32> range_data[] = {
{ prop_name_table+0, prop_name_table+3, }, // any
{ prop_name_table+3, prop_name_table+8, }, // ascii
{ prop_name_table+8, prop_name_table+16, }, // assigned
{ prop_name_table+16, prop_name_table+18, }, // c*
{ prop_name_table+18, prop_name_table+20, }, // cc
{ prop_name_table+20, prop_name_table+22, }, // cf
{ prop_name_table+22, prop_name_table+38, }, // closepunctuation
{ prop_name_table+38, prop_name_table+40, }, // cn
{ prop_name_table+40, prop_name_table+42, }, // co
{ prop_name_table+42, prop_name_table+62, }, // connectorpunctuation
{ prop_name_table+62, prop_name_table+69, }, // control
{ prop_name_table+69, prop_name_table+71, }, // cs
{ prop_name_table+71, prop_name_table+85, }, // currencysymbol
{ prop_name_table+85, prop_name_table+100, }, // dashpunctuation
{ prop_name_table+100, prop_name_table+118, }, // decimaldigitnumber
{ prop_name_table+118, prop_name_table+131, }, // enclosingmark
{ prop_name_table+131, prop_name_table+147, }, // finalpunctuation
{ prop_name_table+147, prop_name_table+153, }, // format
{ prop_name_table+153, prop_name_table+171, }, // initialpunctuation
{ prop_name_table+171, prop_name_table+173, }, // l*
{ prop_name_table+173, prop_name_table+179, }, // letter
{ prop_name_table+179, prop_name_table+191, }, // letternumber
{ prop_name_table+191, prop_name_table+204, }, // lineseparator
{ prop_name_table+204, prop_name_table+206, }, // ll
{ prop_name_table+206, prop_name_table+208, }, // lm
{ prop_name_table+208, prop_name_table+210, }, // lo
{ prop_name_table+210, prop_name_table+225, }, // lowercaseletter
{ prop_name_table+225, prop_name_table+227, }, // lt
{ prop_name_table+227, prop_name_table+229, }, // lu
{ prop_name_table+229, prop_name_table+231, }, // m*
{ prop_name_table+231, prop_name_table+235, }, // mark
{ prop_name_table+235, prop_name_table+245, }, // mathsymbol
{ prop_name_table+245, prop_name_table+247, }, // mc
{ prop_name_table+247, prop_name_table+249, }, // me
{ prop_name_table+249, prop_name_table+251, }, // mn
{ prop_name_table+251, prop_name_table+265, }, // modifierletter
{ prop_name_table+265, prop_name_table+279, }, // modifiersymbol
{ prop_name_table+279, prop_name_table+281, }, // n*
{ prop_name_table+281, prop_name_table+283, }, // nd
{ prop_name_table+283, prop_name_table+285, }, // nl
{ prop_name_table+285, prop_name_table+287, }, // no
{ prop_name_table+287, prop_name_table+301, }, // nonspacingmark
{ prop_name_table+301, prop_name_table+312, }, // notassigned
{ prop_name_table+312, prop_name_table+318, }, // number
{ prop_name_table+318, prop_name_table+333, }, // openpunctuation
{ prop_name_table+333, prop_name_table+338, }, // other
{ prop_name_table+338, prop_name_table+349, }, // otherletter
{ prop_name_table+349, prop_name_table+360, }, // othernumber
{ prop_name_table+360, prop_name_table+376, }, // otherpunctuation
{ prop_name_table+376, prop_name_table+387, }, // othersymbol
{ prop_name_table+387, prop_name_table+389, }, // p*
{ prop_name_table+389, prop_name_table+407, }, // paragraphseparator
{ prop_name_table+407, prop_name_table+409, }, // pc
{ prop_name_table+409, prop_name_table+411, }, // pd
{ prop_name_table+411, prop_name_table+413, }, // pe
{ prop_name_table+413, prop_name_table+415, }, // pf
{ prop_name_table+415, prop_name_table+417, }, // pi
{ prop_name_table+417, prop_name_table+419, }, // po
{ prop_name_table+419, prop_name_table+429, }, // privateuse
{ prop_name_table+429, prop_name_table+431, }, // ps
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -