bool CheckIdValid(string str) { for(int i = 0; i < str.size(); i++) { if(IsLetter(str[i]) == false && IsDigit(str[i]) == false) { ErrorMsg(INVALIDID); return false; } } if(IsLetter(str[0]) == false) { ErrorMsg(INVALIDID); return false; } if(str == "x") { ErrorMsg(XINVALIDID); return false; } return true; }
/** * Starting at 'str' find the next token. A token can be an integer, * an identifier or punctuation symbol. * \return <= 0 we found an error, else, return number of characters parsed. */ static GLint GetToken(struct parse_state *parseState, GLubyte *token) { const GLubyte *str = parseState->pos; GLint i = 0, j = 0; token[0] = 0; /* skip whitespace and comments */ while (str[i] && (IsWhitespace(str[i]) || str[i] == '#')) { if (str[i] == '#') { /* skip comment */ while (str[i] && (str[i] != '\n' && str[i] != '\r')) { i++; } if (str[i] == '\n' || str[i] == '\r') parseState->curLine = str + i + 1; } else { /* skip whitespace */ if (str[i] == '\n' || str[i] == '\r') parseState->curLine = str + i + 1; i++; } } if (str[i] == 0) return -i; /* try matching an integer */ while (str[i] && IsDigit(str[i])) { token[j++] = str[i++]; } if (j > 0 || !str[i]) { token[j] = 0; return i; } /* try matching an identifier */ if (IsLetter(str[i])) { while (str[i] && (IsLetter(str[i]) || IsDigit(str[i]))) { token[j++] = str[i++]; } token[j] = 0; return i; } /* punctuation character */ if (str[i]) { token[0] = str[i++]; token[1] = 0; return i; } /* end of input */ token[0] = 0; return i; }
char ToAsciiUS(char code) { char ascii; ascii=tecladoUS[shift][code]; if( caps && !shift && IsLetter(ascii) ) ascii=ToUpper(ascii); else if( caps && shift && IsLetter(ascii) ) ascii=ToLower(ascii); return ascii; }
int DefaultLanguageCompare(const wchar *a, int a_length, const wchar *b, int b_length, int) { int little = 0, middle = 0; const wchar *p1 = a, *e1 = a + a_length, *p2 = b, *e2 = b + b_length; while(p1 < e1 && p2 < e2) { wchar c1 = *p1++; wchar c2 = *p2++; int level1 = (IsLetter(c1) ? 3 : IsDigit(c1) ? 2 : c1 == ' ' ? 0 : 1); int level2 = (IsLetter(c2) ? 3 : IsDigit(c2) ? 2 : c2 == ' ' ? 0 : 1); if(level1 != level2) return cmp(level1, level2); if(level1 <= 1) { if(c1 != c2) return cmp(c1, c2); continue; } if(level1 == 2) { // digits const wchar *dp1 = --p1, *dp2 = --p2; int res = LangCompareDigits(dp1, dp2, e1, e2); if(res) return res; p1 = dp1; p2 = dp2; continue; } int u1, u2, i1, i2; i1 = ToAscii(u1 = ToUpper(c1)); i2 = ToAscii(u2 = ToUpper(c2)); if(i1 != i2) return i1 >= i2 ? 1 : -1; if(u1 != u2) // different diacritics if(middle == 0) middle = u1 - u2; if(c1 != c2) // different case { if(little == 0) little = (u1 != c1) - (u2 != c2); } } little += 4 * middle; if(little == 0) little = a_length - b_length; return sgn(little); }
bool Scanner::Next() { char currentChar; do { if(lastString) { currentToken = new Token(currentLine, currentPos, END_OF_FILE, DEFAULT, ""); return false; } currentChar = GetChar(); } while(IsSpace(currentChar) || IsTabulationSymbol(currentChar) || IsEndOfLine(currentChar)); if(IsCommentBegin(currentChar)) { char secondChar; if( IsCommentBegin(secondChar = GetChar()) ) { NextLine(); return Next(); } if(secondChar == '*') { while( GetChar() != '*' || !IsCommentBegin(GetChar()) ) {} return Next(); } else BackToPreviousChar(); } if(IsLetter(currentChar)) currentToken = GetIdentificator(currentChar); else if(IsNumber(currentChar)) currentToken = GetNumber(currentChar); else if(IsCharSeparator(currentChar)) currentToken = GetSymbol(currentChar); else if(IsStringSeparator(currentChar)) currentToken = GetString(currentChar); else if(IsSeparator(currentChar)) currentToken = GetSeparator(currentChar); else if(IsSpecialSymbol(currentChar)) currentToken = GetOperation(currentChar); else throw ScannerException(currentLine, currentPos, "Indefinite character: \"" + string(1, currentChar) + "\""); return true; }
String DosInitCaps(const char *name) { for(const char *s = name; *s; s++) if(IsLetter(*s) && IsLower(*s)) return name; return InitCaps(name); }
bool XMLReader::IsNameChar(UnicodeChar c) { // NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender return IsLetter(c) || IsDigit(c) || (c == UnicodeChar('.')) || (c == UnicodeChar('-')) || (c == UnicodeChar('_')) || (c == UnicodeChar(':')); }
unsigned char MSC_IsAlphaNumeric(unsigned char data) { if(IsLetter(data) || MSC_IsNumber(data) || data == ' ') { return TRUE; } return FALSE; }
void TOptions::Add(const UnicodeString & Value) { if (!FNoMoreSwitches && (Value.Length() == 2) && (Value[1] == Value[2]) && (FSwitchMarks.Pos(Value[1]) > 0)) { FNoMoreSwitches = true; } else { bool Switch = false; intptr_t Index = 0; // shut up if (!FNoMoreSwitches && (Value.Length() >= 2) && (FSwitchMarks.Pos(Value[1]) > 0)) { Index = 2; Switch = true; while (Switch && (Index <= Value.Length())) { if (Value.IsDelimiter(FSwitchValueDelimiters, Index)) { break; } // this is to treat /home/martin as parameter, not as switch else if ((Value[Index] != L'?') && !IsLetter(Value[Index])) { Switch = false; break; } ++Index; } } if (Switch) { TOption Option; Option.Type = otSwitch; Option.Name = Value.SubString(2, Index - 2); Option.Value = Value.SubString(Index + 1, Value.Length()); Option.Used = false; FOptions.push_back(Option); } else { TOption Option; Option.Type = otParam; Option.Value = Value; Option.Used = false; FOptions.push_back(Option); ++FParamCount; } } FOriginalOptions = FOptions; }
static GLboolean Parse_Identifier(struct parse_state *parseState, GLubyte *ident) { if (!Parse_Token(parseState, ident)) RETURN_ERROR; if (IsLetter(ident[0])) return GL_TRUE; else RETURN_ERROR1("Expected an identfier"); }
int Scanner::ParseString(Token *token) { int code = Peek(0); if (!IsLetter(code)) return 0; int e = 0; int s = m_offset; while (IsLetter(Peek(0))) { Read(); e++; } token->code = TOKEN_STRING; token->text = m_text.substr(s, e); printf("%s\n", m_text.substr(s, e).c_str()); return 1; }
virtual bool operator()(int pos, const RichPara& para) { WString ptext = para.GetText(); if(pos + ptext.GetLength() > cursor && ptext.GetLength() >= len) { const wchar *q = ptext; const wchar *e = ptext.End() - len; if(cursor >= pos) q += cursor - pos; while(q <= e) { if(compare3(q, upperw, lowerw, len) && (!ww || (q + len == e || !IsLetter(q[len])) && (q == ptext || !IsLetter(q[-1])))) { fpos = int(q - ~ptext + pos); return true; } q++; } } return false; }
WString CSCZGetIndexLetter(const wchar *s, int) { wchar temp[3]; temp[0] = temp[1] = temp[2] = 0; if(*s <= 2047 && IsLetter(*s)) // IsLetter { temp[0] = ToUpper(*s); if(s[1] <= 2047 && IsLetter(s[1])) temp[1] = ToLower(s[1]); if(temp[0] != 'C' || temp[1] != 'h') temp[1] = 0; switch(ToUpper(ToAscii(*s))) { case 'A': case 'E': case 'I': case 'N': case 'O': case 'T': case 'U': case 'Y': temp[0] = ToAscii(temp[0]); break; } } return temp; }
bool XMLReader::IsName(const UnicodeString & name) { // Name ::= (Letter | '_' | ':') (NameChar)* size_t n = name.size(); if (n == 0) return false; UnicodeChar c = name[0]; if ((c == UnicodeChar('_')) || (c == UnicodeChar(':')) || IsLetter(c)) { for (size_t i = 1; i < n; ++i) { if (! IsNameChar(name[i])) return false; } } return true; }
bool XMLReader::ParseName(Name & name) { // Name ::= (Letter | '_' | ':') (NameChar)* UnicodeString temp; UnicodeChar c = ReadChar(); if ((c == UnicodeChar('_')) || (c == UnicodeChar(':')) || IsLetter(c)) { temp += c; while (IsNameChar(PeekChar())) temp += ReadChar(); name.SetName(temp); return true; } return false; }
virtual bool operator()(int pos, const RichPara& para)// A++ bug here.... { if(!IsNull(para.format.label)) { AddLinkRef(link, para.format.label); ref.FindAdd(para.format.label); } for(int i = 0; i < para.part.GetCount(); i++) if(para.part[i].IsText()) { const wchar *s = para.part[i].text; for(;;) { while(!IsLetter(*s) && !IsDigit(*s) && *s) s++; if(*s == '\0') break; StringBuffer sb; while(IsLetter(*s) || IsDigit(*s)) sb.Cat(ToAscii(ToLower(*s++))); words.FindAdd(TopicWordIndex(sb)); } } return false; }
void SetupLexer() { int i; for (i = 0; i < END_OF_FILE + 1; i++) { if (IsLetter(i)) { Scanners[i] = ScanIdentifier; } else if (IsDigit(i)) { Scanners[i] = ScanNumericLiteral; } else { Scanners[i] = ScanBadChar; } } Scanners[END_OF_FILE] = ScanEOF; Scanners['\''] = ScanCharLiteral; Scanners['"'] = ScanStringLiteral; Scanners['+'] = ScanPlus; Scanners['-'] = ScanMinus; Scanners['*'] = ScanStar; Scanners['/'] = ScanSlash; Scanners['%'] = ScanPercent; Scanners['<'] = ScanLess; Scanners['>'] = ScanGreat; Scanners['!'] = ScanExclamation; Scanners['='] = ScanEqual; Scanners['|'] = ScanBar; Scanners['&'] = ScanAmpersand; Scanners['^'] = ScanCaret; Scanners['.'] = ScanDot; Scanners['{'] = ScanLBRACE; Scanners['}'] = ScanRBRACE; Scanners['['] = ScanLBRACKET; Scanners[']'] = ScanRBRACKET; Scanners['('] = ScanLPAREN; Scanners[')'] = ScanRPAREN; Scanners[','] = ScanCOMMA; Scanners[';'] = ScanSEMICOLON; Scanners['~'] = ScanCOMP; Scanners['?'] = ScanQUESTION; Scanners[':'] = ScanCOLON; Scanners['#'] = ScanHASH; Scanners['\n'] = ScanNewLine; }
Bits RichEdit::SpellParagraph(const RichPara& para) { int len = para.GetLength(); Buffer<wchar> text(len); Buffer<int> lang(len); wchar *s = text; int *g = lang; for(int i = 0; i < para.GetCount(); i++) { const RichPara::Part& p = para[i]; if(p.IsText()) { int l = p.text.GetLength(); memcpy(s, p.text, l * sizeof(wchar)); Fill(g, g + l, fixedlang ? fixedlang : p.format.language); s += l; g += l; } else { *s++ = 127; *g++ = 0; } } Bits e; s = text; wchar *end = text + len; while(s < end) { if(IsLetter(*s)) { const wchar *q = s; while(s < end && IsLetter(*s) || s + 1 < end && *s == '\'' && IsLetter(s[1])) s++; if(!SpellWord(q, int(s - q), lang[q - text])) e.Set(int(q - text), true, int(s - q)); } else s++; } return e; }
Token* Scanner::GetIdentificator(char currentChar) { string s = ""; int pos = currentPos, line = currentLine; s += currentChar; while( !IsEndOfLine( currentChar = GetChar() ) && !IsSpace(currentChar) ) { if( IsLetter(currentChar) || IsNumber(currentChar) ) s += currentChar; else { BackToPreviousChar(); break; } } return new Token(line, pos, IsKeyWord(s) ? KEYWORD : IDENTIFIER, IsKeyWord(s) ? keyWord[s] : DEFAULT, s); }
int Automat::WordsAutomat(char* s, char* startCondition, char* endCondition) { char* currentCondition = startCondition; int i = 0; for (; i < strlen(s) && IsLetter(s[i]); i++); char* temp = new char[i]; Copy(temp, s, i); currentCondition = parser->Find(currentCondition, temp); if (!strcmp(currentCondition, endCondition)) { return i; } return 0; }
void SelectPackageDlg::ScanFolder(const String& path, ArrayMap<String, PkData>& nd, const String& nest, Index<String>& dir_exists, const String& prefix) { for(FindFile ff(AppendFileName(path, "*.*")); ff; ff.Next()) if(ff.IsFolder() && !ff.IsHidden()) { dir_exists.Add(ff.GetPath()); String p = ff.GetPath(); bool nw = nd.Find(p) < 0; // Do we have any info loaded about this package? PkData& d = nd.GetAdd(ff.GetPath()); d.package = prefix + ff.GetName(); d.nest = nest; if(nw) { // No cached info available about the folder d.ispackage = IsLetter(*d.package) && d.package.Find('.') < 0; // First heuristic guess d.main = d.ispackage && prefix.GetCount() == 0; // Expect it is main } } }
void CustomString::ToUpper() { int counter = 0; while (m_Chars[counter] != '\0') { //make sure it's a letter if (IsLetter(m_Chars[counter])) { //make sure its lower case if (m_Chars[counter] >= 97 && m_Chars[counter] <= 122) { //move to lower case range m_Chars[counter] -= 32; } } counter++; } }
void CustomString::ToLower() { int counter = 0; while (m_Chars[counter] != '\0') { //make sure it's a letter if (IsLetter(m_Chars[counter])) { //make sure its upper case if (m_Chars[counter] >= 65 && m_Chars[counter] <= 90) { //move to lower case range m_Chars[counter] += 32; } } counter++; } }
void lexerInit(void) { int i; for (i = 0; i < END_OF_FILE + 1; i++) { if (IsDigit(i)) { matchers[i] = matchDouble; }else if (IsLetter(i)) { matchers[i] = matchIdentifier; }else { matchers[i] = matchBadChar; } } matchers['\0'] = matchLineEnd; matchers['+'] = matchPlus; matchers['-'] = matchMinus; matchers['*'] = matchStar; matchers['/'] = matchSlash; matchers['('] = matchLparen; matchers[')'] = matchRparen; matchers['='] = matchEqual; }
int CharFilterDate(int c) { if(IsDigit(c)) return c; const char *s = *s_date_seps_thread ? s_date_seps_thread : s_date_seps_main; bool letters = false; bool upper = false; if(*s == 'a') { letters = true; s++; } else if(*s == 'A') { letters = true; upper = true; s++; } if(letters && IsLetter(c)) return upper ? ToUpper(c) : c; ; int r = 0; while(*s) { if(c == (byte)*s) return c; if(*s == '\r') { s++; while(*s != '\r') { if((byte)*s == c) return r; if(*s == '\0') return 0; s++; } s++; } else r = *s++; } return 0; }
Token* Scanner::GetNumber(char currentChar) { string s = ""; int pos = currentPos, line = currentLine, dot = 0, E = 0; s += currentChar; while( (currentChar = GetChar()) != '\0' && !IsSpace(currentChar)) { if(dot && IsDot(currentChar)) throw ScannerException(currentLine, currentPos, "Too many dots in real number: \"" + GetInvalidToken(pos) + "\""); if(E) { if(IsE(currentChar)) throw ScannerException(currentLine, currentPos, "Too many symbol \"E\" in real number: \"" + GetInvalidToken(pos) + "\""); if(IsNumber(currentChar) || currentChar == '-' || currentChar == '+') { s += currentChar; continue; } else throw ScannerException(currentLine, currentPos, "Invalid real number: \"" + GetInvalidToken(pos) + "\""); } if( IsNumber(currentChar) || IsE(currentChar) || IsDot(currentChar) ) { E += IsE(currentChar); dot += IsDot(currentChar); s += currentChar; } else { if(IsLetter(currentChar)) throw ScannerException(currentLine, currentPos, "Invalid identificator: \"" + GetInvalidToken(pos) + "\""); BackToPreviousChar(); break; } } if(IsE(s[s.length() - 1]) || IsDot(s[s.length() - 1])) throw ScannerException(currentLine, currentPos, "Invalid real number: \"" + s + "\""); return new Token(line, pos, dot || E ? CONST_REAL : CONST_INTEGER, DEFAULT, s); }
WString DefaultGetIndexLetter(const wchar *text, int) { return IsLetter(*text) ? WString(text, 1) : WString(Null); }
int CSCZLanguageCompare(const wchar *a, int a_length, const wchar *b, int b_length, int) { int little = 0, middle = 0; const wchar *p1 = a, *e1 = a + a_length, *p2 = b, *e2 = b + b_length; while(p1 < e1 && p2 < e2) { wchar c1 = *p1++; wchar c2 = *p2++; int level1 = (IsLetter(c1) ? 3 : IsDigit(c1) ? 2 : c1 == ' ' ? 0 : 1); int level2 = (IsLetter(c2) ? 3 : IsDigit(c2) ? 2 : c2 == ' ' ? 0 : 1); if(level1 != level2) return cmp(level1, level2); if(level1 <= 1) { if(c1 != c2) return cmp(c1, c2); continue; } if(level1 == 2) { // digits const wchar *dp1 = --p1, *dp2 = --p2; int res = LangCompareDigits(dp1, dp2, e1, e2); if(res) return res; p1 = dp1; p2 = dp2; continue; } int u1, u2, i1, i2; if((c1 == 'C' || c1 == 'c') && (p1 < e1 && (*p1 == 'H' || *p1 == 'h'))) { // CH i1 = 'H'; u1 = 65535; p1++; } else i1 = ToAscii(u1 = ToUpper(c1)); if((c2 == 'C' || c2 == 'c') && (p2 < e2 && (*p2 == 'H' || *p2 == 'h'))) { // CH i2 = 'H'; u2 = 65535; p2++; } else i2 = ToAscii(u2 = ToUpper(c2)); if(i1 != i2) return i1 >= i2 ? 1 : -1; if(u1 != u2) // different diacritics switch(i1) { case 'A': case 'E': case 'I': case 'N': case 'O': case 'T': case 'U': case 'Y': if(middle == 0) middle = u1 - u2; continue; default: return u1 >= u2 ? 1 : -1; } if(c1 != c2) // different case { if(little == 0) little = (u1 != c1) - (u2 != c2); } } little += 4 * middle; if(little == 0) little = a_length - b_length; return sgn(little); }
/* match_esc() * * The match() function with support for escaping characters such * as '*', '?', '#' and '@' */ int match_esc(const char *mask, const char *name) { const unsigned char *m = (const unsigned char *)mask; const unsigned char *n = (const unsigned char *)name; const unsigned char *ma = (const unsigned char *)mask; const unsigned char *na = (const unsigned char *)name; int wild = 0; int calls = 0; int quote = 0; int match1 = 0; s_assert(mask != NULL); s_assert(name != NULL); if(!mask || !name) return 0; /* if the mask is "*", it matches everything */ if((*m == '*') && (*(m + 1) == '\0')) return 1; while(calls++ < MATCH_MAX_CALLS) { if(quote) quote++; if(quote == 3) quote = 0; if(*m == '\\' && !quote) { m++; quote = 1; continue; } if(!quote && *m == '*') { /* * XXX - shouldn't need to spin here, the mask should have been * collapsed before match is called */ while(*m == '*') m++; wild = 1; ma = m; na = n; if(*m == '\\') { m++; /* This means it is an invalid mask -A1kmm. */ if(!*m) return 0; quote++; continue; } } if(!*m) { if(!*n) return 1; if(quote) return 0; for(m--; (m > (const unsigned char *)mask) && (*m == '?'); m--) ;; if(*m == '*' && (m > (const unsigned char *)mask)) return 1; if(!wild) return 0; m = ma; n = ++na; } else if(!*n) { /* * XXX - shouldn't need to spin here, the mask should have been * collapsed before match is called */ if(quote) return 0; while(*m == '*') m++; return (*m == 0); } if(quote) match1 = *m == 's' ? *n == ' ' : ToLower(*m) == ToLower(*n); else if(*m == '?') match1 = 1; else if(*m == '@') match1 = IsLetter(*n); else if(*m == '#') match1 = IsDigit(*n); else match1 = ToLower(*m) == ToLower(*n); if(match1) { if(*m) m++; if(*n) n++; } else { if(!wild) return 0; m = ma; n = ++na; } } return 0; }
bool MetaLexer::ParseLexProfile(const CoreLib::String & lex) { LinkedList<LexProfileToken> tokens; int ptr = 0; int state = 0; StringBuilder curToken; while (ptr < lex.Length()) { wchar_t curChar = lex[ptr]; wchar_t nextChar = 0; if (ptr+1<lex.Length()) nextChar = lex[ptr+1]; switch (state) { case 0: { if (IsLetter(curChar)) state = 1; else if (IsWhiteSpace(curChar)) ptr ++; else if (curChar == L'{') { state = 2; ptr ++; } else if (curChar == L'=') state = 3; else if (curChar == L'/' && nextChar == L'/') state = 4; else { LexerError err; err.Position = ptr; err.Text = String(L"[Profile Error] Illegal character \'") + curChar + L"\'"; Errors.Add(err); ptr ++; } curToken.Clear(); } break; case 1: { if (IsIdent(curChar)) { curToken.Append(curChar); ptr ++; } else { LexProfileToken tk; tk.str = curToken.ToString(); tk.type = LexProfileToken::Identifier; tokens.AddLast(tk); state = 0; } } break; case 2: { if (curChar == L'}' && (nextChar == L'\r' || nextChar == L'\n' || nextChar == 0) ) { LexProfileToken tk; tk.str = curToken.ToString(); tk.type = LexProfileToken::Regex; tokens.AddLast(tk); ptr ++; state = 0; } else { curToken.Append(curChar); ptr ++; } } break; case 3: { LexProfileToken tk; tk.str = curChar; tk.type = LexProfileToken::Equal; tokens.AddLast(tk); ptr ++; state = 0; } break; case 4: { if (curChar == L'\n') state = 0; else ptr ++; } } } // Parse tokens LinkedNode<LexProfileToken> * l = tokens.FirstNode(); state = 0; String curName, curRegex; try { TokenNames.Clear(); Regex.Clear(); while (l) { curName = ReadProfileToken(l, LexProfileToken::Identifier); l = l->GetNext(); ReadProfileToken(l, LexProfileToken::Equal); l = l->GetNext(); curRegex = ReadProfileToken(l, LexProfileToken::Regex); l = l->GetNext(); TokenNames.Add(curName); Regex.Add(curRegex); if (curName[0] == L'#') Ignore.Add(true); else Ignore.Add(false); } } catch(int) { return false; } return true; }