本文整理汇总了C++中Encoding::encoding方法的典型用法代码示例。如果您正苦于以下问题:C++ Encoding::encoding方法的具体用法?C++ Encoding::encoding怎么用?C++ Encoding::encoding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Encoding
的用法示例。
在下文中一共展示了Encoding::encoding方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: detect_kind
SymbolTable::Kind SymbolTable::detect_kind(STATE, const Symbol* sym) {
std::string str = strings[sym->index()];
size_t size = str.size();
uint8_t* p = reinterpret_cast<uint8_t*>(const_cast<char*>(str.c_str()));
Encoding* e = Encoding::from_index(state, encodings[sym->index()]);
OnigEncodingType* enc = e->encoding();
// Constants start with A-Z, followed by alphanumeric characters or '_' or
// non-ascii character.
if(isupper(*p)) {
uint8_t* e = p + size;
int n = 0, code = 0;
for(++p; p < e; p += n) {
n = Encoding::precise_mbclen(p, e, enc);
if(!ONIGENC_MBCLEN_CHARFOUND_P(n)) {
return SymbolTable::eNormal;
}
n = ONIGENC_MBCLEN_CHARFOUND_LEN(n);
code = ONIGENC_MBC_TO_CODE(enc, p, p + n);
if(!(ONIGENC_IS_CODE_ALNUM(enc, code) || *p == '_' || !ISASCII(*p))) {
return SymbolTable::eNormal;
}
}
return SymbolTable::eConstant;
}
if(p[0] == '@') {
// A class variable begins with @@
if(size > 1 && p[1] == '@') {
return SymbolTable::eCVar;
}
// An instance variable can't start with a digit and can't be just @.
if((size == 1) || (size > 1 && ISDIGIT(p[1]))) {
return SymbolTable::eNormal;
}
// An instance variable begins with @
return SymbolTable::eIVar;
}
// A system variable begins with __
if(size > 2 && p[0] == '_' && p[1] == '_') {
return SymbolTable::eSystem;
}
// Everything else is normal
return SymbolTable::eNormal;
}