/** * 读取输入的字符 * @return [输入的字符] */ char readChar() { char ch; do { ch = getchar(); } while ( !isLetter(ch)); return ch; }
void ST1countdiffer(int *palavrasTotais, int* palavrasDistintas, int *tokensDistintos) { int i = 0, j = 0, pD = 0, pT = 0 ; Item *ordem = mallocSafe(N*sizeof(*ordem)); Key p; sentence *s; for(i = 0; i < M; i++) if(st[i] != NULLitem){ ordem[j] = mallocSafe(sizeof(*(ordem[j]))); ordem[j] = st[i]; if( isLetter(ordem[j]->literal[0] )) for(s = ordem[j]->occurencies; s != NULL; s = s->next)pT++; j++; } mergeSort(ordem, 0, N); p = ordem[0]->literal; if( isLetter(p[0]) ) pD++; for(j = 1; j < N; j++){ if(!eq(p, ordem[j]->lema)){ p = ordem[j]->lema; if(isLetter(p[0])) for(s = ordem[j]->occurencies; s != NULL; s = s->next) pD++; } } *palavrasDistintas = pD; *palavrasTotais = pT; *tokensDistintos = ST1count()+1; free(ordem); }
static bool needsQuotes(const std::string& s) { if (!isLetter(s[0]) && (s[0] != '_')) { return true; } for (int i = 0; i < (int)s.length(); ++i) { char c = s[i]; // peek character char p = (i == (int)s.length() - 1) ? '_' : s[i + 1]; // Identify separators if ((c == '-' && p == '>') || (c == ':' && p == ':')) { // Skip over this symbol ++i; continue; } if (!isDigit(c) && !isLetter(c) && (c != '.')) { // This is an illegal character for an identifier, so we need quotes return true; } } return false; }
/**************************************************************************** Desc: Returns TRUE if the name is a valid XML name ****************************************************************************/ FLMBOOL FLMAPI F_XML::isNameValid( FLMUNICODE * puzName, FLMBYTE * pszName) { FLMBOOL bValid = FALSE; if( puzName) { FLMUNICODE * puzTmp; if( !isLetter( *puzName) && *puzName != FLM_UNICODE_UNDERSCORE && *puzName != FLM_UNICODE_COLON) { goto Exit; } puzTmp = &puzName[ 1]; while( *puzTmp) { if( !isNameChar( *puzTmp)) { goto Exit; } puzTmp++; } } if( pszName) { FLMBYTE * pszTmp; if( !isLetter( *pszName) && *pszName != FLM_UNICODE_UNDERSCORE && *pszName != FLM_UNICODE_COLON) { goto Exit; } pszTmp = &pszName[ 1]; while( *pszTmp) { if( !isNameChar( *pszTmp)) { goto Exit; } pszTmp++; } } bValid = TRUE; Exit: return( bValid); }
bool CStringHelper::isName( const std::string& name ) { if( name.empty() ) return false; if( !isLetter( name[0] ) && name[0]!='_' ) return false; int n = name.size(); for( int i = 1; i < n; ++i ) if( !( isLetter( name[i] ) || isDigit( name[i] ) || ( name[i] == '_' ) ) ) return false; return true; }
bool isValidIdentifier(const std::string& s) { if (s.length() > 0 && (isLetter(s[0]) || s[0] == '_')) { for (size_t i = 1; i < s.length() ; ++i) { if (!( isLetter(s[i]) || (s[i] == '_') || isDigit(s[i]) )) { return false; } } return true; } return false; }
bool isProperVarName(string varName) { if (!isLetter(int(varName[0]))) return false; for (int i=1; i<varName.length(); i++) { if (!isLetter(int(varName[i])) && !isNumber(int(varName[i]))) { if (varName[i]!='-' && varName[i]!='_') return false; } } return true; }
Token DnInLexer::String() { std::string buf; consume(); do { buf.append(1, c); consume(); } while(isDecimal() || isLetter() || isSym()); consume(); return Token(STRING, buf); }
bool Deduction :: compAx(Node * v, Node * ax, int level = 0) { if (v == NULL && ax == NULL) return 1; if (v == NULL || ax == NULL) return 0; if (ax->l == NULL && ax->r == NULL) { assert((int)ax->s.length() == 1); int id = ax->s[0] - 'A'; assert(0 <= id && id <= 2); if (!use[id]) { use[id] = 1; c[id] = v->hash; } if (c[id] != v->hash) { return 0; } } if (isLetter(ax->type)) return 1; if (ax->type != v->type) { //db2(ax->type, v->type); //db("Here"); return 0; } bool ans = 1; ans &= compAx(v->l, ax->l, level + 1); ans &= compAx(v->r, ax->r, level + 1); return ans; }
const char *XMLProcedureCall::MakeValid(const char *pzName, GString &strDestination) { if ( !isLetter(pzName[0]) ) { // prefix invalid XML tag strDestination = "Param_"; } // Replace any other invalid chars with '_' __int64 nLen = (pzName) ? strlen(pzName) : 0; for(int i=0; i < nLen; i++) { if ( isNameChar(pzName[i]) ) strDestination << pzName[i]; else strDestination << '_'; } // If the entire name is invalid - example "12345" // (since an XML Element cannot start with a number XML 1.0) // replace the invalid name with a valid one. if (strDestination.IsEmpty()) strDestination = "Parameter"; return (const char *)strDestination; }
int getLex() { int n; /* --- skip spaces */ while ( Pos < Len && S[Pos] == ' ' ) Pos++; if ( Pos >= Len ) return 0; /* --- check for operand */ n = getOperand(); /* --- check for function/variable/number */ if ( n == 0 ) { if ( isLetter(S[Pos]) ) { getToken(); n = getMathFunc(); if ( n == 0 ) n = getVariable(); } else if ( isDigit(S[Pos]) ) { n = 7; Fvalue = getNumber(); } } Pos++; PrevLex = CurLex; CurLex = n; return n; }
void toMorse(int size,char** args){ char *morse; char output[100000]; int i; int k; int j; int index = 0; for(i = 0; i < size; i++){ for(j = 0; args[i][j] != '\0'; j++){ if(isNumber(args[i][j])){ morse = getMorseNumber(args[i][j]); }else{ if(isLetter(args[i][j])){ morse = getMorseLetter(args[i][j]); } } for(k = 0; morse[k] != '\0'; k++){ output[index++] = morse[k]; } } output[index++] = ' '; } output[index++] = '\0'; toBuffer(output); }
/* A normal Win32 pathname contains no duplicate slashes, except possibly * for a UNC prefix, and does not end with a slash. It may be the empty * string. Normalized Win32 pathnames have the convenient property that * the length of the prefix almost uniquely identifies the type of the path * and whether it is absolute or relative: * * 0 relative to both drive and directory * 1 drive-relative (begins with '\\') * 2 absolute UNC (if first char is '\\'), * else directory-relative (has form "z:foo") * 3 absolute local pathname (begins with "z:\\") */ static int normalizePrefix(const char* path, int len, char* sb, int* sbLen) { char c; int src = 0; while ((src < len) && isSlash(path[src])) src++; if ((len - src >= 2) && isLetter(c = path[src]) && path[src + 1] == ':') { /* Remove leading slashes if followed by drive specifier. This hack is necessary to support file URLs containing drive specifiers (e.g., "file://c:/path"). As a side effect, "/c:/path" can be used as an alternative to "c:/path". */ sb[(*sbLen)++] = c; sb[(*sbLen)++] = ':'; src += 2; } else { src = 0; if ((len >= 2) && isSlash(path[0]) && isSlash(path[1])) { /* UNC pathname: Retain first slash; leave src pointed at second slash so that further slashes will be collapsed into the second slash. The result will be a pathname beginning with "\\\\" followed (most likely) by a host name. */ src = 1; sb[(*sbLen)++] = slash; } } return src; }
SglExprLex::ScanResult SglExprLex::scanNextToken() { ScanResult result; result.type = UNKNOWNTOKEN; result.symbol = 0; start = end; index = start; end = size; if (index == end ) result.type = eol; else if ( state == stText ) result.type = scanTextToken(); else if ( matchesClosePar() ) result.type = getClosePar(); else if ( matchesEscape() ) result = scanSysToken(); else if ( isWhitespace() ) result.type = scanWhitespaceToken(); else if ( isDigit() ) result.type = scanDigitsToken(); else if ( state == stNumber || state == stScale ) result = scanMidNumberToken(); else if ( isLetter() ) result = scanIdentifierToken(); else result = scanSpecialCharToken(); return result; }
/* * Sets the corresponding key properties */ void setKey(unsigned char code) { struct KBDKey key; int state = LOWERCASE; key.shown = FALSE; switch (code) { case LSHIFT_PRESSED: case RSHIFT_PRESSED: keyboard.shiftEnabled = TRUE; break; case LSHIFT_RELEASED: case RSHIFT_RELEASED: keyboard.shiftEnabled = FALSE; break; case CAPS_PRESSED: keyboard.capsEnabled = !keyboard.capsEnabled; break; case CAPS_RELEASED: break; case CTRL_PRESSED: keyboard.ctrlEnabled = TRUE; break; case CTRL_RELEASED: keyboard.ctrlEnabled = FALSE; break; default: if (!(code & 0x80)) { key.shown = TRUE; if ((isLetter(code) && keyboard.capsEnabled && !keyboard.shiftEnabled) || (!keyboard.capsEnabled && keyboard.shiftEnabled) || (!isLetter(code) && keyboard.capsEnabled && keyboard.shiftEnabled)) { state = UPPERCASE; } } break; } key.keyCode = code; key.asciiCode = keysTable[state][code]; if (key.shown) addKey(key.asciiCode); }
int SglExprLex::tryScanTagToken() { if (current() == '0') { ++index; if (!atEnd() && isLetter()) { ++index; while ( !atEnd() && isLetter() && !isHexChar() ) ++index; end = index; ScanResult sr = lookup(); if (sr.symbol && sr.symbol->type() == tagSym) return sr.type; } } return UNKNOWNTOKEN; }
bool SglExprLex::checkExact() { bool exactMatch = index < size && isLetter(); if (exactMatch) scanLetters(); else scanSpecial(); return exactMatch; }
bool Tokenizer::isIdentifierCharacter(char ch) { if (isLetter(ch) || isDigit(ch) || ch == '_') { return true; } return false; }
char* getEmail(char *chaine) { /* [email protected] */ /* token : 01222344444456789 */ int token = 0; char *pChaine, c; int indice; bool isValid = true; fflush(stdin); pChaine = chaine; for (indice = 0; indice < (MAX_SIZE - 1) && isValid; indice++) { c = getchar(); if ((token == 0 && isLetter(c)) // Première lettre USER || (token == 1 && c == '@') // @ || (token == 2 && isLetter(c)) // première lettre DOMAIN || (token == 3 && c == '.') // . || ((token == 4 || token == 5 || token == 6 || token == 7) && isLetter(c))) // lettres TLD { *pChaine = c; *pChaine++; token++; } else if ((token == 1 && isLetter(c)) // Lettres suivantes de USER || (token == 3 && isLetter(c))) // Lettres suivantes de DOMAIN { *pChaine = c; *pChaine++; } else if (c == '\n') break; else { isValid = false; } } if (!isValid || token < 7) printf("Chaine invalide"); *pChaine = '\0'; return chaine; }
Token DnLexer::Id() { std::string buf; int resv = -1; do { buf.append(1, c); consume(); } while(isDecimal() || isLetter() || isSym()); if((resv = isReserved(buf)) != -1){ /* Is this id reserved word? */ return Token(2 + resv, buf); } return Token(ID, buf); }
bool Tokenizer::canStartToken(char ch) { string chStr = string(1, ch); if (isOperatorSubstring(chStr) || isLetter(ch) || isWhitespace(ch) || (ch == '#')) { return true; } return false; }
void processFile(char *text, int n) { size_t text_length = strlen(text); for(int i = 1; i <= n; ++i){ size_t sub_text_length = text_length/i + 2;//accounts for null terminator and rounding errors on divide //split cypher text into i subtexts char *subTextStrings[i]; initializeSubTexts(subTextStrings, text, text_length, sub_text_length, i); //Do frequency analysis //for each character in the substring, get its count and store it -- move for(int stringIndex = 0; stringIndex < i; ++stringIndex){ //for each substring //get the next substring char *currentSubtext = subTextStrings[stringIndex]; size_t currentSubtext_length = strlen(currentSubtext); int frequencyTable[ALEN]; initializeFrequencyTable(frequencyTable, currentSubtext, currentSubtext_length); //Now sort them based on frequency char sortedChars[ALEN+1]; sortedChars[ALEN] = '\0'; initializeSortedChars(sortedChars, frequencyTable); //now map our most frequent characters to the English languages most frequent characters CharHashMap characterMap; for(int i=0; i<ALEN; i++) { char ith_most_frequent_cypertext_char = sortedChars[i]; char ith_most_frequent_english_char = CHFREQ[i]; CharHashMapSet(characterMap, ith_most_frequent_cypertext_char, ith_most_frequent_english_char); } //Now apply the most characters to that of for(int i = 0; i < currentSubtext_length; ++i){ char c = currentSubtext[i]; if(isLetter(c)) { currentSubtext[i] = CharHashMapGet(characterMap, c); //get the corresponding english value } } } //now merge the substrings back together char *result = mergeSubTexts(subTextStrings, text_length, i); printf("%s\n", result); free(result); freeSubTexts(subTextStrings, i); } }
void DefaultLexer::readIdentifier(char startChar) { char c = startChar; putChar(c); skipChar(); c = lookChar(); while (isLetter(c) | isDigit(c)) { putChar(c); skipChar(); c = lookChar(); }; }
void initializeFrequencyTable(int *frequencyTable, char *text, size_t text_length) { // Zero the table bzero(frequencyTable, sizeof(int) * ALEN); for(int index = 0; index < text_length; ++index){ //go through subtext chars char c = text[index]; //get the current char if(isLetter(c)){ //if its alphabetic frequencyTable[c-'A']++; } } }
/* * check one character */ int genxCharClass(genxWriter w, int c) { int ret = 0; if (isXMLChar(w, c)) ret |= GENX_XML_CHAR; if (isNameChar(w, c)) ret |= GENX_NAMECHAR; if (isLetter(w, c)) ret |= GENX_LETTER; return ret; }
/*! \internal Determines whether \a c is a valid instance of production [4]NameChar in the XML 1.0 specification. If it is, true is returned, otherwise false. \sa \l {http://www.w3.org/TR/REC-xml/#NT-NameChar} {Extensible Markup Language (XML) 1.0 (Fourth Edition), [4] NameChar} */ bool QXmlUtils::isNameChar(const QChar c) { return isLetter(c) || isDigit(c) || c.unicode() == '.' || c.unicode() == '-' || c.unicode() == '_' || c.unicode() == ':' || isCombiningChar(c) || isIdeographic(c) || isExtender(c); }
int getAscii(int scanCode){ int asciiCode = -1; scanCode = scanCode & 0xFF; //For scanCodes with more than 1 byte if(__EXTENDED_ != 0){ __EXTENDED_ = 0; if(scanCode <= 83) asciiCode = extendedMakeCodes[scanCode-1]; } else if(scanCode == 0xE0) __EXTENDED_ = 1; else if (scanCode == 170) __L_SHIFT_ = 0; else if(scanCode == 182) __R_SHIFT_ = 0; // If the scanCode is a make code else if (scanCode <= 128){ if(__TILDE_){ if(isVocal(scanCode)) asciiCode = getTildeVocal(scanCode); __TILDE_ = 0; } else if(scanCode == 40){ __TILDE_ = 1; } else if(scanCode == 42) __L_SHIFT_ = 1; else if(scanCode == 54) __R_SHIFT_ = 1; else if (scanCode == 58){ __CURRENT_LEDS += __CAPS_LED; keyboardLeds(__CURRENT_LEDS); __CAPS_LED *= -1; __CAPSLOCK_ = !__CAPSLOCK_; } else if(scanCode == 69){ __CURRENT_LEDS += __NUM_LED; keyboardLeds(__CURRENT_LEDS); __NUM_LED *= -1; __NUMLOCK_ = !__NUMLOCK_; }else if (__CAPSLOCK_ && isLetter(scanCode) ){ if (!__L_SHIFT_ && !__R_SHIFT_) asciiCode = shiftMakeCodes[scanCode-1]; else asciiCode = makeCodes[scanCode-1]; }else if( (__L_SHIFT_ || __R_SHIFT_ || __NUMLOCK_) && isNumber(scanCode)) asciiCode = numpadMakeCodes[scanCode-71]; else if(__L_SHIFT_ || __R_SHIFT_) asciiCode = shiftMakeCodes[scanCode-1]; else asciiCode = makeCodes[scanCode-1]; } return asciiCode; }
void getToken() { char c[] = " "; strcpy(Token, ""); while ( Pos <= Len && ( isLetter(S[Pos]) || isDigit(S[Pos]) ) ) { c[0] = S[Pos]; strcat(Token, c); Pos++; } Pos--; }
/*JUST FOR TEST*/ void swi_test(void) { unsigned char c; uart0_init(); // 波特率115200,8N1(8个数据位,无校验位,1个停止位) led_on(0x9); while(1) { // 从串口接收数据后,判断其是否数字或子母,若是则加1后输出 c = getc(); if (isDigit(c) || isLetter(c)) put_c(c+1); } }
void ST1sort(int mod){ Item* ordem = mallocSafe(N*sizeof(*ordem)); Key p; int i = 0, j = 0; for(i = 0; i < M; i++) if(st[i] != NULLitem){ ordem[j] = mallocSafe(sizeof(*(ordem[j]))); ordem[j++] = st[i]; } mergeSort(ordem, 0, N); if(mod == ALL){ p = ordem[0]->literal; puts(p); for(j = 1; j < N; j++){ if(!eq(p, ordem[j]->literal)){ p = ordem[j]->literal; puts(p); } } } if(mod == WORDS){ p = ordem[0]->literal; if( isLetter(p[0]) ) puts(p); for(j = 1; j < N; j++){ if(!eq(p, ordem[j]->literal)){ p = ordem[j]->literal; if(isLetter(p[0])) puts(p); } } } free(ordem); }