int main(void){ for(char i = 'a'; i <= 'z'; ++i){ assert(is_alpha(i)); assert(!is_digit(i)); assert(is_lower(i)); assert(!is_upper(i)); assert(to_lower(i) == i); assert(to_upper(i) != i); } for(char i = 'A'; i <= 'Z'; ++i){ assert(is_alpha(i)); assert(!is_digit(i)); assert(!is_lower(i)); assert(is_upper(i)); assert(to_lower(i) != i); assert(to_upper(i) == i); } for(char i = '0'; i <= '9'; ++i){ assert(!is_alpha(i)); assert(is_digit(i)); assert(!is_lower(i)); assert(!is_upper(i)); assert(to_lower(i) == i); assert(to_upper(i) == i); } printf("TEST SUCEEDED\n"); return 0; }
/* * Will map a Encrypted character to the Decrypted character * set. Will remove any previous mappings of the given * characters. First parameter is Encrypted character, the * second is the Decrypted character to be mapped to. */ void Key::set(char from, char to) { if (is_upper(from) && (is_upper(to))) { free_both(from, to); // Removes previous mappings of the characters decrypt_map[from] = to; encrypt_map[to] = from; } }
bool detectCapitalUse(string word) { bool all_upper = true, all_lower = true, first = is_upper(word[0]); for(int i=1; i<word.size(); i++) { if (is_lower(word[i])) all_upper = false; if (is_upper(word[i])) all_lower = false; } return all_lower || first && all_upper; }
int main ( int argc , char * argv[] ) { int t = 0; char str1[10001] , str2[10001]; scanf("%d" , &t); getchar(); while ( t-- ) { int * s1 , * s2; s1 = (int *) calloc ( 52 , sizeof(int) ); s2 = (int *) calloc ( 52 , sizeof(int) ); int ls1 = readline(str1); int ls2 = readline(str2); //printf("str1 = %s\n" , str1); //printf("str2 = %s\n" , str2); int i = 0; for ( i = 0 ; i < ls1 ; i++ ) { char ch = str1[i]; if ( is_upper(ch) ) { s1[ch - 'A'] ++; } else { s1[ch - 'a' + 26] ++; } } for ( i = 0 ; i < ls2 ; i++ ) { char ch = str2[i]; if ( is_upper(ch) ) { s2[ch - 'A'] ++; } else { s2[ch - 'a' + 26] ++; } } int count = 0; for ( i = 0 ; i < 52 ; i++ ) { count += (s1[i]<s2[i] ? s1[i] : s2[i]); } printf("%d\n" , count); free(s1); free(s2); } return 0; }
int lca(int v, int const u) { if (is_upper(v, u)) return v; else if (is_upper(u, v)) return u; for (auto i = l; i >= 0; --i) { if (!is_upper(parents[v][i], u)) { v = parents[v][i]; } } return parents[v][0]; }
int main(int argc, char **argv) { int i; if (argc != 2) { ft_perror("usage: ./initials <full name in quotes\"Don Vito\">\n"); return (1); } i = 0; while (argv[1][i] == ' ') i++; while (argv[1][i]) { if (i == 0 || (argv[1][i] != ' ' && argv[1][i - 1] == ' ')) { if (is_upper(argv[1][i])) { ft_putchar(argv[1][i]); } else { ft_putchar(low_to_up(argv[1][i])); } } i++; } ft_putchar('\n'); return (0); }
/* * Returns the Encrypted character that the given Decrypted * character is mapped to, or returns the encrypted null * character if there is no mapping. */ char Key::get_from(char to) { if (is_upper(to)) { return encrypt_map[to]; } else { return to; } }
bool str_is_slot_name(const char* s, fint len) { assert(len >= 0, "shouldn't be negative length"); if (len == 0) { return false; } char c = *s; if (!is_lower(c)) { if (!is_punct(c)) return false; switch (c) { case '^': case '|': case '\\': case '.': if (len == 1) return false; } for (int i = 0; i < len; ) { c = s[i++]; if (! is_punct(c)) return false; switch (c) { case '(': case ')': case '\'': case '\"': case ':': case '[': case ']': return false; } } return true; } for (int i = 1; i < len; ) { c = s[i++]; if (is_id_char(c)) continue; if (c != ':') return false; if (i == len) return true; // this was final ":" if (!is_upper(s[i])) return false; // after ":" must be uppercase if (s[len-1] != ':') return false; // one ":" -> last is ":" } return true; }
/* * Default constructor. Will initialized the both mappings to * their null character. */ Key::Key() { // Maps all upper case characters to the null character for (char c = 'A'; is_upper(c); c++) { decrypt_map[c] = null_decrypt; encrypt_map[c] = null_encrypt; } }
int main(int argc, char* argv[]) { int n,i; int last_pipe[2]; struct grammar g; if (argc != 4) { fatal("Usage: %s <workers number> <grammar file> <starting symbol>\n", argv[0]); } n = atoi(argv[1]); if (n <= 0) { fatal("Number of workers should be a positive integer"); } if (strlen(argv[3]) != 1 || !is_upper(argv[3][0])) { fatal("Starting symbol should be a single nonterminal (uppercase)\n"); } create_pipe(last_pipe); make_loop(n, last_pipe, argv[2]); read_grammar(&g, argv[2]); work(&g, argv[3][0]); for (i = 1; i < n; i++) { if (wait(0) == -1) syserr("Error in wait()\n"); } return 0; }
char* correct_words(char* correct_word,char* word) { char ch; char* res = NULL; int i = 0; int count_lower = 0, count_upper = 0; for(int i = 0; word[i] != '\0'; i++){ if(word[i]>=65 && word[i] < 91){ count_upper += 1; } else count_lower += 1; } if(count_upper > count_lower){ for(; word[i] != '\0'; i++){ ch = word[i]; if(is_lower(ch)){ ch = to_upper(ch); } correct_word[i] = ch; } } else{ for(i = 0; word[i] != '\0'; i++){ ch = word[i]; if(is_upper(ch)){ ch = to_lower(ch); } correct_word[i] = ch; } } correct_word[i] = '\0'; res = correct_word; return res; }
/* * Returns the Decrypted character that the given Encrypted * character is mapped to, or returns the decrypted null * character if there is no mapping. */ char Key::get_to(char from) { if (is_upper(from)) { return decrypt_map[from]; } else { return from; } }
/** * Returns 1 if the string 's' is only made of uppercase letters, * according to the given alphabet, 0 otherwise. */ int is_sequence_of_uppercase_letters(const unichar* s,const Alphabet* alphabet) { int i=0; while (s[i]!='\0') { if (!is_upper(s[i],alphabet)) return 0; i++; } return 1; }
/* Will remove the given Encrypted character's mapping if it * existes. */ void Key::remove(char from) { if (is_upper(from)) { if (decrypt_map[from] != null_decrypt) { // Checks if it is actually mapped encrypt_map[decrypt_map[from]] = null_encrypt; decrypt_map[from] = null_decrypt; } } }
/*----------------------------------------------------------------------------- ** Function: init_type() ** Purpose: This is the initialization routine for this file. This ** has to be called before some of the macros in |type.h| ** will work as described. It does no harm to call this ** initialization more than once. It just takes some time. ** ** Note that this function is for internal purposes ** only. The normal user should call |init_bibtool()| ** instead. ** Arguments: none ** Returns: nothing **___________________________________________________ */ void init_type() /* */ { register int i; /* */ /* */ for ( i = 0; i < 256; ++i ) /* */ { trans_lower[i] = is_upper(i)?to_lower(i):i; /* */ trans_upper[i] = is_lower(i)?to_upper(i):i; /* */ trans_id[i] = i; /* */ } /* */ } /*------------------------*/
static RegInfo *tf_reg_compile_fl(const char *pattern, int optimize, const char *file, int line) { RegInfo *ri; const char *emsg, *s; int eoffset, n; /* PCRE_DOTALL optimizes patterns starting with ".*" */ int options = PCRE_DOLLAR_ENDONLY | PCRE_DOTALL | PCRE_CASELESS; ri = dmalloc(NULL, sizeof(RegInfo), file, line); if (!ri) return NULL; ri->extra = NULL; ri->ovector = NULL; ri->Str = NULL; ri->links = 1; if (warn_curly_re && (s = estrchr(pattern, '{', '\\')) && (is_digit(s[1]) || s[1] == ',')) { wprintf("regexp contains '{', which has a new meaning in version 5.0. " "(This warning can be disabled with '/set warn_curly_re=off'.)"); } for (s = pattern; *s; s++) { if (*s == '\\') { if (s[1]) s++; } else if (is_upper(*s)) { options &= ~PCRE_CASELESS; break; } } ri->re = pcre_compile((char*)pattern, options, &emsg, &eoffset, re_tables); if (!ri->re) { /* don't trust emsg to be non-NULL or NUL-terminated */ eprintf("regexp error: character %d: %.128s", eoffset, emsg ? emsg : "unknown error"); goto tf_reg_compile_error; } n = pcre_info(ri->re, NULL, NULL); if (n < 0) goto tf_reg_compile_error; ri->ovecsize = 3 * (n + 1); ri->ovector = dmalloc(NULL, sizeof(int) * ri->ovecsize, file, line); if (!ri->ovector) goto tf_reg_compile_error; if (optimize) { ri->extra = pcre_study(ri->re, 0, &emsg); if (emsg) { eprintf("regexp study error: %.128s", emsg); goto tf_reg_compile_error; } } return ri; tf_reg_compile_error: tf_reg_free(ri); return NULL; }
// Change the case of the current character. First check lower and then upper. If it is not a letter, it gets returned // unchanged. int chcase(int ch) { // Translate lowercase. if(is_lower(ch)) return upcase[ch]; // Translate uppercase. if(is_upper(ch)) return lowcase[ch]; // Let the rest pass. return ch; }
/** * @fn Вычисляет новый символ, закодированный по цезарю, с учетом зацикливания. */ short offset(short symbol, int counter){ short new_symbol = symbol + counter; if (is_digit(symbol)){ return cycle(new_symbol, '0', '9'); } if (is_lower(symbol)){ return cycle(new_symbol, 'a', 'z'); } if (is_upper(symbol)){ return cycle(new_symbol, 'A', 'Z'); } return symbol; }
bool match(const char *str1, const char *str2) { char *ita = (char *)str1; char *itb = (char *)str2; while(*ita || *itb){ if(!(*ita)) return false; if(!(*itb)) return false; char a = *ita; char b = *itb; if(is_upper(a)) a = to_lower(a); if(is_upper(b)) b = to_lower(b); if(!(a == b)) return false; ita++; itb++; } return true; }
/* * Encode char if it's a letter, or return original */ char encode(char src, int key) { if (is_upper(src)) { return rotate(src, 'A', key, 26); } if (is_lower(src)) { return rotate(src, 'a', key, 26); } else { return src; } }
CFSArray<CFSWString> do_utterances(CFSWString s) { CFSWString res = empty_str; CFSArray<CFSWString> res_array; if (s.GetLength() == 1) res_array.AddItem(s); else for (INTPTR i = 0; i < s.GetLength(); i++) { CFSWString c = s.GetAt(i); CFSWString pc = res.GetAt(res.GetLength() - 1); CFSWString nc = s.GetAt(i + 1); CFSWString nnc = s.GetAt(i + 2); if (is_ending(c) && is_whitespace(nc) && is_upper(nnc)) { res.Trim(); res_array.AddItem(res); res = empty_str; } else if (is_tab(c)) { if (res.GetLength() > 0) { res.Trim(); res_array.AddItem(res); res = empty_str; } } else res += c; } res.Trim(); if (res.GetLength() > 0) { while (is_ending(res.GetAt(res.GetLength() - 1))) { res.Delete(res.GetLength() - 1, 1); } res_array.AddItem(res); } for (INTPTR i=0; i < res_array.GetSize(); i++) { if (is_ending(res_array[i].GetAt(res_array[i].GetLength()-1))) res_array[i].Delete( res_array[i].GetLength()-1, 1 ); } return res_array; }
int minimumNumber(int n, std::string p) { int t[4] = {0}; for (std::size_t i = 0; i < p.size(); ++i) if (is_upper(p[i])) t[0] = 1; else if (is_lower(p[i])) t[1] = 1; else if (is_digit(p[i])) t[2] = 1; else if (is_special(p[i])) t[3] = 1; int s = 0; for (int i = 0; i < 4; ++i) s += t[i]; if (n < 6) return std::max(6 - n, 4 - s); else return 4 - s; }
laser_return get_laser_return( const packet& packet , unsigned int block , unsigned int laser , const boost::posix_time::ptime& timestamp , double angularSpeed , bool legacy) { laser_return r; r.id = laser + ( is_upper( block ) ? 0 : 32 ); r.intensity = packet.blocks[block].lasers[laser].intensity(); r.range = double( packet.blocks[block].lasers[laser].range() ) / 500; if (legacy) { r.timestamp = timestamp + time_offset( block, laser ); r.azimuth = azimuth( packet, block, laser, angularSpeed ); } else { r.timestamp = timestamp - hdl64_s2_fw_v48::time_delay( block, laser ); r.azimuth = hdl64_s2_fw_v48::azimuth(packet, block, laser, angularSpeed); } return r; }
//input: *c=='[' **pc==':' static u16 bracket_class(u8 *c,u8 **pc,u8 **sc,u8 not,u8 sc_folded) { u8 char_class[CHAR_CLASS_MAX+1];//don't forget the 0 terminating char u16 r=bracket_char_class_get(c,pc,not,sc_folded,&char_class[0]); if(r!=OK) return r; if((STREQ(char_class,"alnum")&&is_alnum(**sc)) ||(STREQ(char_class,"alpha")&&is_alpha(**sc)) ||(STREQ(char_class,"blank")&&is_blank(**sc)) ||(STREQ(char_class,"cntrl")&&is_cntrl(**sc)) ||(STREQ(char_class,"digit")&&is_digit(**sc)) ||(STREQ(char_class,"graph")&&is_graph(**sc)) ||(STREQ(char_class,"lower")&&is_lower(**sc)) ||(STREQ(char_class,"print")&&is_print(**sc)) ||(STREQ(char_class,"punct")&&is_punct(**sc)) ||(STREQ(char_class,"space")&&is_space(**sc)) ||(STREQ(char_class,"upper")&&is_upper(**sc)) ||(STREQ(char_class,"xdigit")&&is_xdigit(**sc))) return bracket_matched(c,pc,not); *c=*(*pc)++; return OK; }
static bool is_identifier_first(char c) { return is_upper(c) || is_lower(c) || c == '_'; }
unsigned int is_letter(unsigned char ch) { return (is_upper(ch) || is_lower(ch)); }
// Is a character a letter? We presume a letter must be either in the upper or lower case tables (even if it gets // translated to itself). bool isletter(int ch) { return is_upper(ch) || is_lower(ch); }
/* * Will remove all the mappings and reset them to the null * null characters of the given sets. */ void Key::clear() { for (char c = 'A'; is_upper(c); c++) { decrypt_map[c] = null_decrypt; encrypt_map[c] = null_encrypt; } }
/** * Explores the given dictionary to match the given word. */ static void explore_dic(int offset,unichar* word,int pos_word,Dictionary* d,SpellCheckConfig* cfg, Ustring* output,SpellCheckHypothesis* *list,int base,Ustring* inflected) { int original_offset=offset; int original_base=base; int final,n_transitions,inf_code; int z=save_output(output); int size_pairs=cfg->pairs->nbelems; offset=read_dictionary_state(d,offset,&final,&n_transitions,&inf_code); if (final) { if (word[pos_word]=='\0') { /* If we have a match */ deal_with_matches(d,inflected->str,inf_code,output,cfg,base,list); } base=output->len; } /* If we are at the end of the token, then we stop */ if (word[pos_word]=='\0') { return; } unsigned int l2=inflected->len; unichar c; int dest_offset; for (int i=0;i<n_transitions;i++) { restore_output(z,output); offset=read_dictionary_transition(d,offset,&c,&dest_offset,output); /* For backup_output, see comment below */ int backup_output=save_output(output); if (c==word[pos_word] || word[pos_word]==u_toupper(c)) { u_strcat(inflected,c); explore_dic(dest_offset,word,pos_word+1,d,cfg,output,list,base,inflected); } else { /* We deal with the SP_SWAP case, made of 2 SP_CHANGE_XXX */ if (cfg->current_errors!=cfg->max_errors && cfg->current_SP_SWAP!=cfg->max_SP_SWAP && is_letter_swap(cfg,word,pos_word,inflected,c)) { /* We don't modify the number of errors since we override an existing * SP_CHANGE_XXX one */ cfg->current_SP_SWAP++; /* We override the previous change */ int a=cfg->pairs->tab[cfg->pairs->nbelems-2]; int b=cfg->pairs->tab[cfg->pairs->nbelems-1]; cfg->pairs->tab[cfg->pairs->nbelems-2]=pos_word-1; cfg->pairs->tab[cfg->pairs->nbelems-1]=SP_SWAP_DEFAULT; u_strcat(inflected,c); explore_dic(dest_offset,word,pos_word+1,d,cfg,output,list,base,inflected); cfg->pairs->tab[cfg->pairs->nbelems-2]=a; cfg->pairs->tab[cfg->pairs->nbelems-1]=b; cfg->current_SP_SWAP--; } else /* We deal with the SP_CHANGE case */ if (cfg->current_errors!=cfg->max_errors && cfg->current_SP_CHANGE!=cfg->max_SP_CHANGE /* We want letters, not spaces or anything else */ && is_letter(c,NULL) /* We do not allow the replacement of a lowercase letter by an uppercase * letter at the beginning of the word like Niserable, unless the whole word * is in uppercase or the letter is the same, module the case */ && (cfg->allow_uppercase_initial || pos_word>0 || (!is_upper(word[0],NULL) || is_upper(word[1],NULL) || word[0]==u_toupper(c)))) { cfg->current_errors++; cfg->current_SP_CHANGE++; /* Now we test all possible kinds of change */ vector_int_add(cfg->pairs,pos_word); u_strcat(inflected,c); /* We always add the default case */ vector_int_add(cfg->pairs,SP_CHANGE_DEFAULT); int n_elem=cfg->pairs->nbelems; explore_dic(dest_offset,word,pos_word+1,d,cfg,output,list,base,inflected); /* Then we test the accent case */ if (u_deaccentuate(c)==u_deaccentuate(word[pos_word])) { /* After a call to explore_dic, we must restore the output. * But, when dealing with SP_CHANGE_XXX ops, we must restore the * output including the output associated to the current transition, * which is why we don't use z (output before the current transition) * but backup_output */ restore_output(backup_output,output); cfg->pairs->nbelems=n_elem; cfg->pairs->tab[cfg->pairs->nbelems-1]=SP_CHANGE_DIACRITIC; explore_dic(dest_offset,word,pos_word+1,d,cfg,output,list,base,inflected); } /* And the case variations */ if (u_tolower(c)==u_tolower(word[pos_word])) { restore_output(backup_output,output); cfg->pairs->nbelems=n_elem; cfg->pairs->tab[cfg->pairs->nbelems-1]=SP_CHANGE_CASE; explore_dic(dest_offset,word,pos_word+1,d,cfg,output,list,base,inflected); } /* And finally the position on keyboard */ if (areCloseOnKeyboard(c,word[pos_word],cfg->keyboard)) { restore_output(backup_output,output); cfg->pairs->nbelems=n_elem; cfg->pairs->tab[cfg->pairs->nbelems-1]=SP_CHANGE_KEYBOARD; explore_dic(dest_offset,word,pos_word+1,d,cfg,output,list,base,inflected); } cfg->pairs->nbelems=size_pairs; cfg->current_errors--; cfg->current_SP_CHANGE--; /* End of the SP_CHANGE case */ } } restore_output(backup_output,output); truncate(inflected,l2); /* Now we deal with the SP_SUPPR case */ if (cfg->current_errors!=cfg->max_errors && cfg->current_SP_SUPPR!=cfg->max_SP_SUPPR /* We want letters, not spaces or anything else */ && is_letter(c,NULL)) { cfg->current_errors++; cfg->current_SP_SUPPR++; vector_int_add(cfg->pairs,pos_word); if (pos_word>=1 && c==word[pos_word-1]) { vector_int_add(cfg->pairs,SP_SUPPR_DOUBLE); } else { vector_int_add(cfg->pairs,SP_SUPPR_DEFAULT); } u_strcat(inflected,c); explore_dic(dest_offset,word,pos_word,d,cfg,output,list,original_base,inflected); truncate(inflected,l2); cfg->pairs->nbelems=size_pairs; cfg->current_errors--; cfg->current_SP_SUPPR--; } } restore_output(z,output); /* Finally, we deal with the SP_INSERT case, by calling again the current * function with the same parameters, except pos_word that will be increased of 1 */ if (cfg->current_errors!=cfg->max_errors && cfg->current_SP_INSERT!=cfg->max_SP_INSERT /* We want letters, not spaces or anything else */ && is_letter(word[pos_word],NULL) /* We do not allow the insertion of a capital letter at the beginning of * the word like Astreet, unless the whole word is in uppercase like ASTREET */ && (cfg->allow_uppercase_initial || pos_word>0 || (!is_upper(word[0],NULL) || is_upper(word[1],NULL)))) { cfg->current_errors++; cfg->current_SP_INSERT++; vector_int_add(cfg->pairs,pos_word); if (pos_word>=1 && word[pos_word]==word[pos_word-1]) { vector_int_add(cfg->pairs,SP_INSERT_DOUBLE); } else { vector_int_add(cfg->pairs,SP_INSERT_DEFAULT); } explore_dic(original_offset,word,pos_word+1,d,cfg,output,list,original_base,inflected); truncate(inflected,l2); cfg->pairs->nbelems=size_pairs; cfg->current_errors--; cfg->current_SP_INSERT--; } /* Finally, we restore the output as it was when we enter the function */ restore_output(z,output); }
bool is_alpha(char ch) { return is_lower(ch) || is_upper(ch); }