wxString FbExportTreeContext::Normalize(const wxString &filename, bool translit) { const wxString forbidden = wxT("*?\\/:\"<>|"); wxString oldname = filename; oldname.Trim(false).Trim(true); bool space = false; wxString newname; size_t length = oldname.Length(); for (size_t i = 0; i < length; i++) { wxChar ch = oldname[i]; if (0 <= ch && ch < 0x20) continue; if (forbidden.Find(ch) != wxNOT_FOUND) continue; if (ch == (wxChar)0x2116) ch = (wxChar)0x004E; if (ch == (wxChar)0x0401) ch = (wxChar)0x0415; if (ch == (wxChar)0x0451) ch = (wxChar)0x0435; if (!IsAlphaNumeric(ch)) ch = 0x20; bool skip = space && ch == 0x20; space = ch == 0x20; if (skip) continue; if (m_underscores && space) ch = (wxChar)0x5F; newname << ch; } newname = newname.Trim(false).Trim(true).Left(fbMAX_FILENAME_LENGTH); wxEncodingConverter ec; ec.Init(wxFONTENCODING_UNICODE, wxFONTENCODING_CP1251, wxCONVERT_SUBSTITUTE); newname = ec.Convert(newname); if (translit) { const wxChar * transchar[32] = { wxT("a"), wxT("b"), wxT("v"), wxT("g"), wxT("d"), wxT("e"), wxT("zh"), wxT("z"), wxT("i"), wxT("j"), wxT("k"), wxT("l"), wxT("m"), wxT("n"), wxT("o"), wxT("p"), wxT("r"), wxT("s"), wxT("t"), wxT("u"), wxT("f"), wxT("h"), wxT("c"), wxT("ch"), wxT("sh"), wxT("shh"), wxT("'"), wxT("y"), wxT("'"), wxT("e"), wxT("yu"), wxT("ya"), }; oldname = newname; newname.Empty(); size_t length = oldname.Length(); for (size_t i = 0; i < length; i++) { unsigned char ch = (wxChar)oldname[i] % 0x100; if (0xC0 <= ch && ch <= 0xDF) { newname << wxString(transchar[ch - 0xC0]).Upper(); } else if (0xE0 <= ch && ch <= 0xFF) { newname << wxString(transchar[ch - 0xE0]); } else newname << wxChar(ch); } } ec.Init(wxFONTENCODING_CP1251, wxFONTENCODING_UNICODE, wxCONVERT_SUBSTITUTE); newname = ec.Convert(newname); while (newname.Left(1) == wxT(".")) newname = newname.Mid(1); while (newname.Right(1) == wxT(".")) newname = newname.Mid(0, newname.Len()-1); return newname; }
std::string MakeAlphaNumeric( const std::string& who ) { std::string result; for( unsigned int i = 0; i < who.size(); ++i ) { char t = who[ i ]; if( IsAlphaNumeric( t ) ) result += t; } return result; }
bool nwxString::ContainsAlphaNumeric(const wxString &s) { size_t nLen = s.Len(); size_t i; wxChar x; bool bRtn = false; for(i = 0; i < nLen; i++) { x = s.GetChar(i); if(IsAlphaNumeric(x)) { bRtn = true; i = nLen; // loop exit } } return bRtn; }
//----------------------------------------------------------------------------- // Update scan codes for foreign keyboards //----------------------------------------------------------------------------- void ButtonCode_UpdateScanCodeLayout( ) { // reset the keyboard memcpy( s_pScanToButtonCode, s_pScanToButtonCode_QWERTY, sizeof(s_pScanToButtonCode) ); #if !defined( _X360 ) // fix up keyboard layout for other languages HKL currentKb = ::GetKeyboardLayout( 0 ); HKL englishKb = ::LoadKeyboardLayout("00000409", 0); if (englishKb && englishKb != currentKb) { for ( int i = 0; i < ARRAYSIZE(s_pScanToButtonCode); i++ ) { // take the english/QWERTY ButtonCode_t code = s_pScanToButtonCode_QWERTY[ i ]; // only remap printable keys if ( code != KEY_NONE && code != KEY_BACKQUOTE && ( IsAlphaNumeric( code ) || IsPunctuation( code ) ) ) { // get it's virtual key based on the old layout int vk = ::MapVirtualKeyEx( i, 1, englishKb ); // turn in into a scancode on the new layout int newScanCode = ::MapVirtualKeyEx( vk, 0, currentKb ); // strip off any high bits newScanCode &= 0x0000007F; // set in the new layout s_pScanToButtonCode[newScanCode] = code; } } } s_pScanToButtonCode[0] = KEY_NONE; #endif }
CgaToken CgaLexer::GetToken() { // Eat white space while (IsWhiteSpace(c)) { MoveNext(); } // Handle identifiers if (IsAlpha(c)) { CGAString identifier; identifier += c; MoveNext(); while (IsAlphaNumeric(c) || c == '.') { identifier += c; MoveNext(); } if (identifier == "true") { return CreateToken(CgaTokenType::True, "true"); } else if (identifier == "false") { return CreateToken(CgaTokenType::False, "false"); } else if (identifier == "var") { return CreateToken(CgaTokenType::Var, "var"); } else { return CreateToken(CgaTokenType::Identifier, identifier); } } // Handle Numbers if (IsDigit(c) || c == '.') { CGAString snum; while (IsDigit(c)) { snum += c; MoveNext(); } if (c == '.') { snum += c; MoveNext(); while (IsDigit(c)) { snum += c; MoveNext(); } } float num = static_cast<float>(atof(snum.c_str())); if (c == 'r') { snum += c; MoveNext(); // Eat 'r' return CreateToken(CgaTokenType::ArgNumber, snum, num); } else { return CreateToken(CgaTokenType::Number, snum); } } // Handle string if (c == '\"') { MoveNext(); // Eat " CGAString value; while (c != '\"') { value += c; MoveNext(); if (stream.eof()) break; } MoveNext(); // Eat " return CreateToken(CgaTokenType::String, value); } // Handle Comments if (c == '#') { // Eat till end of line while (c != '\n' && !stream.eof()) { MoveNext(); } MoveNext(); // Eat \n } // Handle additive operators if (c == '+' || c == '-') { char lastChar = c; CGAString op; op += c; MoveNext(); // Handle arrow op '->' if (lastChar == '-' && c == '>') { op += c; MoveNext(); return CreateToken(CgaTokenType::Arrow, op); } return CreateToken(CgaTokenType::BinaryOp, op); } // Handle multiplicative operators if (c == '*' || c == '/') { CGAString op; op += c; MoveNext(); return CreateToken(CgaTokenType::BinaryOp, op); } // Handle conditional operators if (c == '<' || c == '>' || c == '!' || c == '=') { char lastChar = c; CGAString op; op += c; MoveNext(); if (c != '=') { // Is not an '=='. Emit an assign token ('=') return CreateToken(CgaTokenType::Assign, op); } if ( (lastChar == '<' && c == '=') || (lastChar == '>' && c == '=') || (lastChar == '!' && c == '=') || (lastChar == '=' && c == '=') ) { op += c; MoveNext(); } return CreateToken(CgaTokenType::BinaryOp, op); } // Handle End of file if (stream.eof()) { return CreateToken(CgaTokenType::Eof, 0); } CgaTokenType Type = CgaTokenType::Unknown; if (c == ';') Type = CgaTokenType::Semicolon; if (c == ',') Type = CgaTokenType::Comma; if (c == '(') Type = CgaTokenType::ParenOpen; if (c == ')') Type = CgaTokenType::ParenClose; if (c == '{') Type = CgaTokenType::CurlOpen; if (c == '}') Type = CgaTokenType::CurlClose; if (c == '|') Type = CgaTokenType::Pipe; if (c == ':') Type = CgaTokenType::Colon; if (c == '~') Type = CgaTokenType::Epsillon; CGAString value(1, c); MoveNext(); return CreateToken(Type, value); }
static inline bool IsAlphaNumericOrUnderscore(char c) { return IsAlphaNumeric(c) || (c == '_'); }
bool IsPunctuation(const char &ch) { return !IsAlphaNumeric(ch) && IsVisible(ch); }