int main( void ) { char *text, *word, *ptr, *wordEnd; size_t len; char chr, tmpchr; puts( "This program search character in a text and print all words, that contain given character." ); puts( "Enter character(a-z, A-Z, 0-9):" ); while( 1 ) { chr = (char)getchar(); if( IsGraph( tmpchr = (char)getchar() ) ) { ungetc( tmpchr, stdin ); } if( IsAlnum( chr ) == false ) { puts( "Wrong character, try again:" ); } else { break; } } text = Input(); if( text == NULL ) { puts( "Not enough memory." ); return 1; } ptr = text; while( wordEnd = FindWord( ptr, chr ) ) { len = 1; word = wordEnd; while( IsAlnum( word[-1] ) && word >= text ) { word--; len++; } word = memcpy( malloc( len + 1 ), word, len ); if( word == NULL ) { puts( "Memory is not enough" ); break; } else { word[len] = 0; printf( "\"%s\" is the word, that contain '%c'\n", word, chr ); free( word ); } ptr = wordEnd + 1; } free( text ); return 0; }
static int _object_get_callback(Jsi_Tree *tree, Jsi_TreeEntry *hPtr, void *data) { Jsi_Value *v; objwalker *ow = data; Jsi_DString *dStr = ow->dStr; int len; char *str; if ((hPtr->f.bits.dontenum)) return JSI_OK; v = Jsi_TreeValueGet(hPtr); if ((ow->quote&JSI_OUTPUT_JSON) && v && v->vt == JSI_VT_UNDEF) return JSI_OK; str = Jsi_TreeKeyGet(hPtr); char *cp = Jsi_DSValue(dStr); len = Jsi_DSLength(dStr); if (len>=2 && cp[len-2] != '{') Jsi_DSAppend(dStr, ", ", NULL); if (((ow->quote&JSI_OUTPUT_JSON) == 0 || (ow->quote&JSI_JSON_STRICT) == 0) && IsAlnum(str) && !IsKeyword(tree->interp, str)) Jsi_DSAppend(dStr, str, NULL); else /* JSON/spaces, etc requires quoting the name. */ Jsi_DSAppend(dStr, "\"", str, "\"", NULL); Jsi_DSAppend(dStr, ":", NULL); ow->depth++; jsiValueGetString(tree->interp, v, dStr, ow); ow->depth--; return JSI_OK; }
/// check if this is this atext as defined in RFC 2822 static inline bool IsATextChar(char c) { // VZ: '|' should appear here too normally but I'm too tired of seeing // Mahogany highlighting URLs improperly in Bugzilla reports (where // an email address is always shown in '|'-separated columns), so // I removed it return IsAlnum(c) || strchr("!#$%&'*+-/=?^_`{}~", c); }
static void crule_getword(char* word, int* wordlenp, size_t maxlen, const char** ruleptr) { char *word_ptr; word_ptr = word; while ((size_t)(word_ptr - word) < maxlen && (IsAlnum(**ruleptr) || **ruleptr == '*' || **ruleptr == '?' || **ruleptr == '.' || **ruleptr == '-')) *word_ptr++ = *(*ruleptr)++; *word_ptr = '\0'; *wordlenp = word_ptr - word; }
/* * Convert ISO-8601 format string to time_t value. */ bool parse_time(const char *value, time_t *time) { size_t len; char *tmp; int i; struct tm tm; char junk[2]; /* tmp = replace( value, !isalnum, ' ' ) */ tmp = pgut_malloc(strlen(value) + + 1); len = 0; for (i = 0; value[i]; i++) tmp[len++] = (IsAlnum(value[i]) ? value[i] : ' '); tmp[len] = '\0'; /* parse for "YYYY-MM-DD HH:MI:SS" */ memset(&tm, 0, sizeof(tm)); tm.tm_year = 0; /* tm_year is year - 1900 */ tm.tm_mon = 0; /* tm_mon is 0 - 11 */ tm.tm_mday = 1; /* tm_mday is 1 - 31 */ tm.tm_hour = 0; tm.tm_min = 0; tm.tm_sec = 0; i = sscanf(tmp, "%04d %02d %02d %02d %02d %02d%1s", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec, junk); free(tmp); if (i < 1 || 6 < i) return false; /* adjust year */ if (tm.tm_year < 100) tm.tm_year += 2000 - 1900; else if (tm.tm_year >= 1900) tm.tm_year -= 1900; /* adjust month */ if (i > 1) tm.tm_mon -= 1; /* determine whether Daylight Saving Time is in effect */ tm.tm_isdst = -1; *time = mktime(&tm); return true; }
bool CfgParser::ReadName(const char *&p, string &name, int &index) { SkipWhitesNL(p); const char *n_begin, *n_end; int _index = 0; n_begin = p; while(IsAlnum(*p) || *p == '_' || *p=='@' || *p=='$') p++; n_end = p; SkipWhites(p); if(*p=='[') { p++; SkipWhites(p); _index = ParseInt(p); SkipWhites(p); if(*p!=']') return false; p++; SkipWhites(p); } else if(*p=='*') { p++; _index = auto_index++; SkipWhites(p); } if(*p==':' || *p=='=') p++; else { SkipWhitesNL(p); if(*p!='{') return false; } name.assign(n_begin, n_end-n_begin); index = _index; return true; }
/** Parse an OpenFirmware device path node into the caller-allocated OFW_NODE structure, and advance in the input string. The node format is mostly parsed after IEEE 1275-1994, 3.2.1.1 "Node names" (a leading slash is expected and not returned): /driver-name@unit-address[:device-arguments][<LF>] A single trailing <LF> character is consumed but not returned. A trailing <LF> or NUL character terminates the device path. The function relies on ASCII encoding. @param[in out] Ptr Address of the pointer pointing to the start of the node string. After successful parsing *Ptr is set to the byte immediately following the consumed characters. On error it points to the byte that caused the error. The input string is never modified. @param[out] OfwNode The members of this structure point into the input string, designating components of the node. Separators are never included. If "device-arguments" is missing, then DeviceArguments.Ptr is set to NULL. All components that are present have nonzero length. If the call doesn't succeed, the contents of this structure is indeterminate. @param[out] IsFinal In case of successul parsing, this parameter signals whether the node just parsed is the final node in the device path. The call after a final node will attempt to start parsing the next path. If the call doesn't succeed, then this parameter is not changed. @retval RETURN_SUCCESS Parsing successful. @retval RETURN_NOT_FOUND Parsing terminated. *Ptr was (and is) pointing to an empty string. @retval RETURN_INVALID_PARAMETER Parse error. **/ STATIC RETURN_STATUS ParseOfwNode ( IN OUT CONST CHAR8 **Ptr, OUT OFW_NODE *OfwNode, OUT BOOLEAN *IsFinal ) { // // A leading slash is expected. End of string is tolerated. // switch (**Ptr) { case '\0': return RETURN_NOT_FOUND; case '/': ++*Ptr; break; default: return RETURN_INVALID_PARAMETER; } // // driver-name // OfwNode->DriverName.Ptr = *Ptr; OfwNode->DriverName.Len = 0; while (OfwNode->DriverName.Len < 32 && (IsAlnum (**Ptr) || IsDriverNamePunct (**Ptr)) ) { ++*Ptr; ++OfwNode->DriverName.Len; } if (OfwNode->DriverName.Len == 0 || OfwNode->DriverName.Len == 32) { return RETURN_INVALID_PARAMETER; } // // unit-address // if (**Ptr != '@') { return RETURN_INVALID_PARAMETER; } ++*Ptr; OfwNode->UnitAddress.Ptr = *Ptr; OfwNode->UnitAddress.Len = 0; while (IsPrintNotDelim (**Ptr)) { ++*Ptr; ++OfwNode->UnitAddress.Len; } if (OfwNode->UnitAddress.Len == 0) { return RETURN_INVALID_PARAMETER; } // // device-arguments, may be omitted // OfwNode->DeviceArguments.Len = 0; if (**Ptr == ':') { ++*Ptr; OfwNode->DeviceArguments.Ptr = *Ptr; while (IsPrintNotDelim (**Ptr)) { ++*Ptr; ++OfwNode->DeviceArguments.Len; } if (OfwNode->DeviceArguments.Len == 0) { return RETURN_INVALID_PARAMETER; } } else { OfwNode->DeviceArguments.Ptr = NULL; } switch (**Ptr) { case '\n': ++*Ptr; // // fall through // case '\0': *IsFinal = TRUE; break; case '/': *IsFinal = FALSE; break; default: return RETURN_INVALID_PARAMETER; } DEBUG (( DEBUG_VERBOSE, "%a: DriverName=\"%.*a\" UnitAddress=\"%.*a\" DeviceArguments=\"%.*a\"\n", __FUNCTION__, OfwNode->DriverName.Len, OfwNode->DriverName.Ptr, OfwNode->UnitAddress.Len, OfwNode->UnitAddress.Ptr, OfwNode->DeviceArguments.Len, OfwNode->DeviceArguments.Ptr == NULL ? "" : OfwNode->DeviceArguments.Ptr )); return RETURN_SUCCESS; }
/* When we're called, p points to the "\r\n" and so p+2 is the start of the next line. What we try to do here is to detect the case when there is an extension somewhere near the end of the line -- if it's incomplete, we can be (almost) sure that the URL continues on the next line. OTOH, if we have the full extension here, chances are that the URL is not wrapped. */ static bool CanBeWrapped(const wxChar *p) { // we consider any alphanumeric string of 3 characters an extension // but we have separate arrays of known extensions of other lengths static const wxChar *extensions1 = { // this one is actually a string and not an array as like this we can use // strchr() below _T("cCfhZ"), }; static const wxChar *extensions2[] = { _T("cc"), _T("gz"), }; static const wxChar *extensions4[] = { _T("html"), _T("jpeg"), _T("tiff"), }; if ( !IsAlnum(p[-1]) ) { // can't be part of an extension, so, by default, consider that the URL // can be wrapped return true; } if ( p[-2] == '.' ) { if ( wxStrchr(extensions1, p[-1]) ) { // we seem to have a one letter extension at the end return false; } } else if ( !IsAlnum(p[-2]) ) { // as above -- we don't know, assume it can be wrapped return true; } else if ( p[-3] == '.' ) { for ( size_t n = 0; n < WXSIZEOF(extensions2); n++ ) { if ( p[-2] == extensions2[n][0] && p[-1] == extensions2[n][1] ) { // line ends with a full 2 letter extension return false; } } } else if ( !IsAlnum(p[-3]) ) { // as above -- we don't know, assume it can be wrapped return true; } else if ( p[-4] == '.' ) { for ( size_t n = 0; n < WXSIZEOF(extensions4); n++ ) { const wxChar * const ext = extensions4[n]; if ( wxStrncmp(p - 3, ext, 3) == 0 && p[2] == ext[3] ) { // looks like a long extension got wrapped return true; } } // it doesn't look that extension is continued on the next line, // consider this to be the end of the URL return false; } else if ( p[-5] == '.' ) { for ( size_t n = 0; n < WXSIZEOF(extensions4); n++ ) { if ( wxStrncmp(p - 4, extensions4[n], 4) == 0 ) { // line ends with an extension, shouldn't wrap normally return false; } } return true; } else // no periods at all anywhere in sight { return true; } // we get here if we had a period near the end of the string but we didn't // recognize the extension following it -- so try to understand whether this // is a wrapped extension by checking if the next char is an alnum one return IsAlnum(p[2]); }
/// checks a character to be a valid part of an URL inline bool IsURLChar(char c) { return IsAlnum(c) || IsURLMark(c) || IsURLReserved(c) || c == '%' || c == '#' || c == '[' || c == ']'; }
bool Hotkey::IsAlnum() const { return IsAlnum(m_key, m_mod_keys); }
int eval_alnum(char c) { return (0 != IsAlnum(c)); }