SglExprLex::ScanResult SglExprLex::scanIdentifierToken() { while ( !atEnd() && isAlphaNum() ) ++index; end = index; return lookup(); }
/** * Get next token in the current string expr. * Uses the data in m_expr pointed to by m_e to * produce m_tokenType and m_token, set m_err in case of an error */ void CondParser::getToken() { m_tokenType = NOTHING; m_token.resize(0); //printf("\tgetToken e:{%c}, ascii=%i, col=%i\n", *e, *e, e-expr); // skip over whitespaces while (*m_e == ' ' || *m_e == '\t') // space or tab { m_e++; } // check for end of expression if (*m_e=='\0') { // token is still empty m_tokenType = DELIMITER; return; } // check for parentheses if (*m_e == '(' || *m_e == ')') { m_tokenType = DELIMITER; m_token += *m_e++; return; } // check for operators (delimeters) if (isDelimiter(*m_e)) { m_tokenType = DELIMITER; while (isDelimiter(*m_e)) { m_token += *m_e++; } return; } // check for variables if (isAlpha(*m_e)) { m_tokenType = VARIABLE; while (isAlphaNum(*m_e)) { m_token += *m_e++; } return; } // something unknown is found, wrong characters -> a syntax error m_tokenType = UNKNOWN; while (*m_e) { m_token += *m_e++; } m_err = QCString("Syntax error in part '")+m_token+"'"; return; }
// https://secure.wikimedia.org/wikipedia/en/wiki/URL_encoding void urlEncode(char* _out, uint32_t _max, const StringView& _str) { _max--; // need space for zero terminator const char* str = _str.getPtr(); const char* term = _str.getTerm(); uint32_t ii = 0; for (char ch = *str++ ; str <= term && ii < _max ; ch = *str++ ) { if (isAlphaNum(ch) || ch == '-' || ch == '_' || ch == '.' || ch == '~') { _out[ii++] = ch; } else if (ii+3 < _max) { _out[ii++] = '%'; _out[ii++] = toHex(ch>>4); _out[ii++] = toHex(ch); } }
bool CCmdLine::read(FILE *f) { #ifdef _WIN32 if (isInteractive()) fputc('>', stdout); if (fgets(s, CMDLINELENGTH, f) == NULL) return false; #else if (isInteractive()) { char * line = readline("> "); strncpy(s, line, CMDLINELENGTH); add_history(s); free(line); } else { if (fgets(s, CMDLINELENGTH, f) == NULL) return false; } #endif int i = 0; while (s[i] != 0 && i < CMDLINELENGTH) { if (s[i] == '\n' || s[i] == '\r') { s[i] = 0; break; } i++; } cmd = s; while (isWhitespace(cmd[0])) cmd++; par = cmd; while (isAlphaNum(*par)) par++; if (par[0] != 0) { par[0] = 0; par++; } return true; }
bool CCmdLine::getSymbol(int &value) { int n = 0; char s[MAXSYMLEN+1]; while (n<MAXSYMLEN && (isAlphaNum(*par) || (*par == '_'))) { s[n++] = par[0]; par++; } s[n] = 0; if (n == 0) return false; int i = 0; while (symtable[i].name[0]) { if (strcmp(s,symtable[i].name) == 0) { value = symtable[i].value; return true; } i++; } return true; }
bool TokenStream::tryIdentifier(Token& token, const ParseLocation& loc) { std::string str; if (!isAlpha(cin->peek())) return false; str += (char)cin->get(); while (isAlphaNum(cin->peek())) str += (char)cin->get(); token = Token(str,Token::TY_IDENTIFIER,loc); return true; }
bool isPalindrome(string s) { if(s.empty()) return true; size_t i = 0, j = s.size() - 1; for(;i < j;++i, --j){ while(i < j && !isAlphaNum(s[i])) ++i; if(i >= j) return true; while(i < j && !isAlphaNum(s[j])) --j; if(i >= j) return true; if(!isEq(s[i], s[j])) return false; } return true; }
/** * For CGI, alphanum headers with optional dashes are mapped to UPP3R_CAS3. This * function can be used to reject non-alphanum/dash headers that would end up with * the same mapping (e.g. upp3r_cas3 and upp3r-cas3 would end up the same, and * potentially collide each other in the receiving application). This is * used to fix CVE-2015-7519. */ static bool containsNonAlphaNumDash(const LString &s) { const LString::Part *part = s.start; while (part != NULL) { for (unsigned int i = 0; i < part->size; i++) { const char start = part->data[i]; if (start != '-' && !isAlphaNum(start)) { return true; } } part = part->next; } return false; }
int main() { char s1[41] = "\0"; char s2[21] = "\0"; char c = '\0'; char userInput[50] = "\0"; unsigned int i = 0; unsigned int j = 0; unsigned int k = 0; srand(time(NULL)); //Generate random upper case array string for (i; i < 40; i++) { *(s1 + i) = randUpperChar(); } // printf("%s\n", s1); printf("Let's reset some letters!\nPlease input at least 2 upper case letters to reset followed by a space and a \"reset\" character.\n"); printf("Or type \"No\" to quit.\n"); while (fgets(userInput, 20, stdin) != NULL) { if (*userInput == 'N' && *(userInput + 1) == 'o') break; // printf("%s", userInput); while (isUpperAlpha(*(userInput + j)) && j < 20) { *(s2 +j) = *(userInput + j); j++; } // printf("%s\n", s2); c = *(userInput + j + 1); // printf("%c / %d\n", c, j); if (j < 2 || !isAlphaNum(c)) { printf("Invalid input.\nPlease input at least 2 upper case letters to reset followed by a space and a \"reset\" character.\n"); printf("Or type \"No\" to quit.\n"); } else { printf("s1 = {\"%s\"}\n", s1); printf("s2 = {\"%s\"}\n", s2); printf("c = {\"%c\"}\n", c); strfilter(s1, s2, c); } for (k; k < 20; k++) *(s2 + k) = '\0'; c = '\0'; j = 0; k = 0; } return 0; }
bool parseIdentifier(File& file, std::string& out_string) { if(*file.str == '"') return parseString(file, out_string); if(!isAlpha(*file.str)) { std::cout << "Line " << file.current_line_num << ": Unexpected char '" << *file.str << "'. Identifier must start with an alpha char!\n"; std::cout << (int)*file.str << "\n"; return false; } const char* start = file.str; file.str++; while(isAlphaNum(*file.str) || *file.str == '_') file.str++; out_string = std::string(start, file.str - start); return true; }
bool SglExprLex::isSpecial() const { return !isWhitespace() && !isAlphaNum(); }