Esempio n. 1
0
char *prepare_str_old (char *x) {
  char *s = prep_buf;
  int i=0, j=0;

  while (x[i] && !is_letter (x[i])) {
    i++;
  }

  while (x[i]) {
    while (is_letter (x[i])) {
      ADD_CHAR(x[i++]);
    }
    while (x[i] && !is_letter (x[i])) {
      i++;
    }
    if (!x[i])
    {
      ADD_CHAR('+');
      break;
    }
    ADD_CHAR('+');
  }

  ADD_CHAR(0);

  char *res = dl_malloc (j);
  if (res == NULL) {
    return res;
  }
  memcpy (res, prep_buf, j);

  return res;
}
void check_palindrome( char* str )
{
	int retv = 1;
	int start = 0;
	int end = strlen( str ) - 1;

	while( start < end )
	{
		if( !is_letter( str[start] ) )
			start++;
		else if( !is_letter( str[end] ) )
			end--;
		else if( str[start] == str[end] || abs( str[start] - str[end] )
				== 'A' - 'a' )
		{
			start++;
			end--;
		}
		else
		{
			retv = 0;
			goto out;
		}
	}

out:
	if( retv )
		printf( "is palindrome\n" );
	else
		printf( "is not palindrome\n" );
	return;
}
Esempio n. 3
0
static void local_next_token (void) {
  skip_wspc ();
  cur_token_quoted = 0;
  if (buffer_pos >= buffer_end) {
    cur_token_len = -3;
    cur_token_real_len = 0;
    return;
  }
  char c = *buffer_pos;
  if (is_letter (c)) {
    cur_token = buffer_pos;
    while (buffer_pos < buffer_end && is_letter (*buffer_pos)) {
      buffer_pos ++;
    }
    if (buffer_pos < buffer_end) {
      cur_token_len = buffer_pos - cur_token;
    } else {
      cur_token_real_len = buffer_pos - cur_token;
      cur_token_len = -3;
    }
    return;
  } else if (c == '"') {
    cur_token_quoted = 1;
    cur_token = buffer_pos ++;
    int backslashed = 0;
    while (buffer_pos < buffer_end && (*buffer_pos != '"' || backslashed)) {
      if (*buffer_pos == '\\') {
        backslashed ^= 1;
      } else {
        backslashed = 0;
      }
      buffer_pos ++;
    }
    if (*buffer_pos == '"') {
      buffer_pos ++;
      expand_backslashed (cur_token + 1, buffer_pos - cur_token - 2);
      if (exp_buffer_pos < 0) {
        cur_token_len = -2;
      } else {
        cur_token_len = exp_buffer_pos;
        cur_token = exp_buffer;
      }
    } else {
      cur_token_len = -2;
    }
    return;
  } else {
    if (c) {
      cur_token = buffer_pos ++;
      cur_token_len = 1;
    } else {
      cur_token_len = -3;
      cur_token_real_len = 0;
    }
  }
}
Esempio n. 4
0
	bool is_identifier_token(const std::string& token)
	{
		if (not is_letter(token[0]) and not (token[0] == '_')) return false;
		for (size_t i = 1; i < token.size(); i++) {
			if (not is_letter(token[i]) and not is_number(token[i]) and not (token[i] == '_')) {
				return false;
			}
		}
		return true;
	}
Esempio n. 5
0
int tokenize(char *s, char *strings[]) {
  if (s == NULL || strcmp(s, "") == 0 || strings == NULL) {
    int j;
    for (j = 0; j < 10; j++) {
      strings[j][0] = 0;
    }
    return 0;
  }

  int count = 0;

  int i = 0; // index into string s
  int word_index = 0; // index into word we're constructing
  int starts_with_letter = 0; 
  while (s[i] != 0) {

    // see if it starts with a letter
    if (word_index == 0 && is_letter(s[i])) {
      starts_with_letter = 1;
    }

    if (s[i] == ' ') {
      strings[count][word_index] = 0; // null-terminate
      word_index = 0;
      count++;
      starts_with_letter = 0;
    }
    else {
      if ((!starts_with_letter && s[i] != ',' && s[i] != ';' && s[i] != ')') || 
        (starts_with_letter && (is_letter(s[i]) || s[i] == '_' || '0' < s[i] && s[i] < '9'))) {
      	strings[count][word_index] = s[i];
      	word_index++;
      }
    }

    i++;

  }
  strings[count][word_index] = 0;

  int retVal = count+1;

  count++;

  for (; count < 10; count++)
    strings[count][0] = 0;

  return retVal;
}
Esempio n. 6
0
int				ft_check_param(char *fmt, int i, t_printf *conv)
{
	int		a;

	if (conv->wc_arg == 0)
	{
		a = i;
		i += is_flag(fmt, i, &conv[0]);
		i += is_mfw(fmt, i, &conv[0]);
		i += is_precision(fmt, i, &conv[0]);
		i += is_length(fmt, i, &conv[0]);
		while (fmt[i] == ' ')
			i++;
		i += is_letter(fmt[i], &conv[0]);
		conv->size_param = i - a;
		if (conv->letter == '*')
		{
			conv->prec_err = 0;
			conv->flag_err = 0;
			conv->size_param = ft_get_param(fmt, a, conv) + 1;
			ft_check_letter(fmt, a + conv->size_param - 1, conv);
			if (conv->display_errors == 1 && conv->count_errors++ >= 0)
				ft_error_msg(1, fmt, a, i - a);
		}
	}
	return ((conv->error_letter != NULL
				&& ft_strcmp(conv->error_letter, "eol") == 0) ? 0 : 1);
}
Esempio n. 7
0
/**
 *  Handles parsing the source code to create an identifier
 *
 *  @return the token representing the identifier
 */
Token Scanner::handle_identifier() {
    Token t;
    std::string s = "";
    
    // assign position
    t.line_position = line_number;
    t.col_position = col_number;
    
    while (position < source_length && (is_letter(source[position]) || is_digit(source[position]))) {
        s += source[position];
        position++;
        col_number++;
    }
    
    // check if s is a keyword
    if (is_keyword(s)) {
        return handle_keyword(t, s);
    }
    
    // return identifier - try putting this above the is_keyword thing
    // and pass a reference into the keyword so it'll change it if needed,
    // then just return t out here
    t.kind = IDENTIFIER;
    t.identifier = s;
    return t;
}
Esempio n. 8
0
/*************************************************************
 * Read characters from character list file and if character *
 * is letter assign characters to c1, c2 and c3.             *
 * If file has not three letters assign NULL to input char   *
 * by order. For ex. file has two letters assign proper      *
 * letters to c1 and c2 and assign NULL to c3. If file has   *
 * four letters assign c1, c2 and c3 first three letters.    *
 * Return number of letters in character list file.          *
 * Do not forget to count only proper letters with your      *
 * is_letter function. Return number of letters not chars    *
 *************************************************************/
int
read_character_list(FILE* f_in_ptr, char *c1, char *c2, char *c3)
{
    int counter = 0;

    int i, a, b;
    char ch, char1, char2, char3;

    for(i=0; i!=EOF; i=a) {
        a=fscanf(f_in_ptr, "%c",&ch);
        b=is_letter(ch);
        if(counter==2 && b==1) {
            *c3 = ch;
            counter++;
        }
        if(counter==1 && b==1) {
            *c2 = ch;
            counter++;
        }
        if(counter==0 && b==1) {
            *c1 = ch;
            counter++;
        }

    }

    return counter;
}
Esempio n. 9
0
/* Test whether the character can be the first character of
 * a NCName. */
static bool is_first_char(uint32_t ch)
{
	/* Refer http://www.w3.org/TR/REC-xml/ for detail */
	if (((ch >= 'a') && (ch <= 'z')) ||
		((ch >= 'A') && (ch <= 'Z')) ||
		(ch == '_') || (ch == ':') ||
		((ch >= 0xC0) && (ch <= 0xD6)) ||
		((ch >= 0xD8) && (ch <= 0xF6)) ||
		((ch >= 0xF8) && (ch <= 0x2FF)) ||
		((ch >= 0x370) && (ch <= 0x37D)) ||
		((ch >= 0x37F) && (ch <= 0x1FFF)) ||
		((ch >= 0x200C) && (ch <= 0x200D)) ||
		((ch >= 0x2070) && (ch <= 0x218F)) ||
		((ch >= 0x2C00) && (ch <= 0x2FEF)) ||
		((ch >= 0x3001) && (ch <= 0xD7FF)) ||
		((ch >= 0xF900) && (ch <= 0xFDCF)) ||
		((ch >= 0xFDF0) && (ch <= 0xFFFD)) ||
		((ch >= 0x10000) && (ch <= 0xEFFFF)))
		return true;

	if (is_letter(ch) || ch == (uint32_t) '_' || ch == (uint32_t) ':') {
		return true;
	} 

	return false;
}
Esempio n. 10
0
/* 针对lua中出现的对话选项后面紧跟其执行的函数名这种情况进行特殊处理,
   因为抽取出来的字符串往往包含了对话其后的函数名,需要去掉,否则一旦翻
   译的时候他们把函数名写错了,问题将非常大 */
int
get_tail_func_name_len(char* pBuffer, int nStrLen){
	char	cOld, *pStr;
	int	nLen = 0;
	int	nIsFuncName = 1;

	cOld = pBuffer[nStrLen];
	pBuffer[nStrLen] = '\0';

	pStr = strrchr(pBuffer, '/');
	if (pStr != NULL){
		nLen = nStrLen - (int)(pStr - pBuffer);
		pStr++;
		if ( *pStr != '#'){
			while ( *pStr != '\0' ){
				if ( (!is_letter(*pStr)) &&
				     (!is_digit(*pStr)) &&
				     (!is_ungderline(*pStr))&&
				     (!is_bracket(*pStr)) ){
					nIsFuncName = 0;
					break;
				}
				pStr++;
			}
		}
		if ( nIsFuncName == 0 )
			nLen = 0;
	}

	pBuffer[nStrLen] = cOld;
	return nLen;
}
Esempio n. 11
0
int is_alphanum (int c)
{
    if (is_letter(c))
	return 1;
    if (c >= '0' && c <= '9')
	return 1;
    return 0;
}
Esempio n. 12
0
int main()
{
	//check if it is a vowel
	printf("%d == %d\n", is_vowel('a'), true);
	printf("%d == %d\n", is_vowel('h'), false);

	//check if it is a lettere
	printf("%d == %d\n", is_letter('a'), true);
	printf("%d == %d\n", is_letter('#'), false);

	//checks if it is a consonant
	printf("%d == %d\n", is_consonant('a'), false);
	printf("%d == %d\n", is_consonant('c'), true);
	printf("%d == %d\n", is_consonant('Z'),true);
	printf("%d == %d\n", is_consonant('1'), false);

	return false;
}
Esempio n. 13
0
String* get_word(FILE *f, char *head, String *token)
{
    while(is_letter(*head) && !feof(f))
    {
        str_push(token, *head);
        *head=fgetc(f);
    }

    return token;
}
Esempio n. 14
0
String auxiliary::findPath(const Sidemarks& From, const Sidemarks& To, const bool& AllowMiddle)
{
  if(From==To  || From.type()!= To.type() || From.getEigenvalue()!=To.getEigenvalue())
  {
    return "";
  }
  typedef std::pair<Sidemarks,String>  state;
  std::list<state> Trace;
  Trace.push_back(state(From,"E")); // E means: Empty. It will be deleted before return
  while(true)
  {
    Sidemarks next_pos=Trace.front().first;
    String path=Trace.front().second;
    const char last_sign=path.back();
    const char last_move= is_letter(last_sign) ? last_sign : path[path.length()-2];
    const String sides(AllowMiddle ? "FRUBLD" : next_pos);
    C_FOR_STR(sides,s)
    {
      if(*s==last_move)
      {
	continue;
      }
      for(int mode=0;mode<3+(2*AllowMiddle);++mode)
      {
	String op;
	op.push_back(*s);
	switch(mode)
	{
	  case 1:  // inverse
	    op.push_back('\'');
	    break;
	  case 2:  // double
	    op.push_back('2');
	    break;
	  case 3:
	    op.push_back('|'); // middle side 
	    break;
	  case 4:
	    op.append("||");
	    break;
	  default:
	    ; // SKIP
	}
	Sidemarks next=next_pos+op;
	if(next==To)
	{
	  path.erase(path.begin());
	  return path+op;
	}
	Trace.push_back(state(next,path+op));
      }
    }
    Trace.pop_front();
  }
}
Esempio n. 15
0
File: ext.c Progetto: infoburp/gawk
awk_bool_t
make_builtin(const awk_ext_func_t *funcinfo)
{
	NODE *symbol, *f;
	INSTRUCTION *b;
	const char *sp;
	char c;
	const char *name = funcinfo->name;
	int count = funcinfo->num_expected_args;

	sp = name;
	if (sp == NULL || *sp == '\0')
		fatal(_("make_builtin: missing function name"));

	if (! is_letter(*sp))
		return awk_false;

	for (sp++; (c = *sp++) != '\0';) {
		if (! is_identifier_char(c))
			return awk_false;
	}

	f = lookup(name);

	if (f != NULL) {
		if (f->type == Node_func) {
			/* user-defined function */
			fatal(_("make_builtin: can't redefine function `%s'"), name);
		} else if (f->type == Node_ext_func) {
			/* multiple extension() calls etc. */ 
			if (do_lint)
				lintwarn(_("make_builtin: function `%s' already defined"), name);
			return awk_false;
		} else
			/* variable name etc. */ 
			fatal(_("make_builtin: function name `%s' previously defined"), name);
	} else if (check_special(name) >= 0)
		fatal(_("make_builtin: can't use gawk built-in `%s' as function name"), name); 

	if (count < 0)
		fatal(_("make_builtin: negative argument count for function `%s'"),
				name);

	b = bcalloc(Op_symbol, 1, 0);
	b->extfunc = funcinfo->function;
	b->expr_count = count;

	/* NB: extension sub must return something */

       	symbol = install_symbol(estrdup(name, strlen(name)), Node_ext_func);
	symbol->code_ptr = b;
	track_ext_func(name);
	return awk_true;
}
Esempio n. 16
0
void to_lower(char *string, int length) {

	for (int i = 0; i < length; i++) {
	    
		if (is_letter(string[i])) {
		    
			if (string[i] >= 'A' && string[i] <= 'Z') {
				string[i] = string[i] - ('A' - 'a');
			}
		}
	}
}
Esempio n. 17
0
// 对标识符的处理部分
Token TokenAnalyze::identifier(char ch)
{
	string value;
	do
	{
		value += ch;
	}while (filein.get(ch) && (is_letter(ch) || is_digit(ch)));
	filein.unget();  // 回退一个字符
	if(is_reseve(value))  // 是保留字的时候返回保留字的类型
		return Token(value,reservedWord[value],line_number);
	else // 不是的时候返回标识符
		return Token(value,token_type::IDEN,line_number);
}
Esempio n. 18
0
String* get_token_data(FILE *f, char *head)
{
    String *token=0;

    skip(f, head);
    if(is_letter(*head))
    {
        token=str_init("");
        get_word(f, head, token);
    }

    return token;
}
Esempio n. 19
0
// Verify the correctness of the letter_digit_table[].
void Signature::verify_tables() {
    static bool verified = false;
    if (!verified) {
        for (jchar ch = 0; ch < 512; ch++) {
            if (('A' <= ch && ch <= 'Z') ||
                    ('a' <= ch && ch <= 'z') || ch == '_' || ch == '$') {
                GUARANTEE(is_letter_or_digit(ch), "sanity");
                GUARANTEE(is_letter(ch),"sanity");
            } else if ('0' <= ch && ch <= '9') {
                GUARANTEE(is_letter_or_digit(ch), "sanity");
                GUARANTEE(!is_letter(ch),"sanity");
            } else if (ch >= 128) {
                GUARANTEE(is_letter_or_digit(ch), "sanity");
                GUARANTEE(is_letter(ch),"sanity");
            } else {
                GUARANTEE(!is_letter_or_digit(ch), "sanity");
                GUARANTEE(!is_letter(ch),"sanity");
            }
        }
        verified = true;
    }
}
Esempio n. 20
0
/**
 * This function takes a text sequence and returns the list of its tokens.
 * The tokenization is done word by word. If the given alphabet is NULL,
 * then letters are tested with the 'u_is_letter' function.
 */
struct list_ustring* tokenize_word_by_word(const unichar* text,const Alphabet* alphabet) {
if (text==NULL) {
   fatal_error("NULL text in tokenize_word_by_word\n");
}
unichar tmp[4096];
int pos=0;
struct list_ustring* tokens=NULL;
struct list_ustring* end=NULL;
while (text[pos]!='\0') {
   if (is_letter(text[pos],alphabet)) {
      /* If we have a letter, we must read the whole letter sequence */
      int j=0;
      while (j<(4096-1) && is_letter(text[pos],alphabet)) {
         /* The while loop end if we find a non letter character,
          * including '\0' */
         tmp[j++]=text[pos++];
      }
      if (j==(4096-1)) {
         fatal_error("Word too long in tokenize_word_by_word\n");
      }
      tmp[j]='\0';
   } else {
      /* If we have a non letter, it is a token by itself */
      tmp[0]=text[pos];
      tmp[1]='\0';
      pos++;
   }
   /* Then, we add the 'tmp' token to our list */
   if (tokens==NULL) {
      /* If the list was empty */
      tokens=new_list_ustring(tmp);
      end=tokens;
   } else {
      end->next=new_list_ustring(tmp);
      end=end->next;
   }
}
return tokens;
}
Esempio n. 21
0
File: ext.c Progetto: infoburp/gawk
void
make_old_builtin(const char *name, NODE *(*func)(int), int count)	/* temporary */
{
	NODE *symbol, *f;
	INSTRUCTION *b;
	const char *sp;
	char c;

	sp = name;
	if (sp == NULL || *sp == '\0')
		fatal(_("extension: missing function name"));

	if (! is_letter(*sp))
		fatal(_("extension: illegal character `%c' in function name `%s'"), *sp, name);

	for (sp++; (c = *sp++) != '\0';) {
		if (! is_identifier_char(c))
			fatal(_("extension: illegal character `%c' in function name `%s'"), c, name);
	}

	f = lookup(name);

	if (f != NULL) {
		if (f->type == Node_func) {
			/* user-defined function */
			fatal(_("extension: can't redefine function `%s'"), name);
		} else if (f->type == Node_ext_func) {
			/* multiple extension() calls etc. */ 
			if (do_lint)
				lintwarn(_("extension: function `%s' already defined"), name);
			return;
		} else
			/* variable name etc. */ 
			fatal(_("extension: function name `%s' previously defined"), name);
	} else if (check_special(name) >= 0)
		fatal(_("extension: can't use gawk built-in `%s' as function name"), name); 

	if (count < 0)
		fatal(_("make_builtin: negative argument count for function `%s'"),
				name);

	b = bcalloc(Op_symbol, 1, 0);
	b->builtin = func;
	b->expr_count = count;

	/* NB: extension sub must return something */

       	symbol = install_symbol(estrdup(name, strlen(name)), Node_old_ext_func);
	symbol->code_ptr = b;
	track_ext_func(name);
}
Esempio n. 22
0
/**
 * From Gordon's paper, the gen function.
 * @param pos  The offset from an anchor square.
 * @param word The word generated so far.
 * @param rack The player's current rack.
 * @param arc  An Arc to the initial state of the GADDAG.
 */
void gen(int pos, char* word, uint8_t* rack, ARC* arc, int spaces) {
    // If a letter L is on this square, go_on
    // What square am I on?
    #ifdef DEBUG_
    print_spaces(spaces);
    printf("in gen, %d, Word: %s,", pos, word);
    print_rack(rack);
    #endif
    uint8_t blank_position = game_state.num_distinct_letters - 1;
    uint8_t i, k;
    char letter = is_letter(
        game_state.game_board[game_state.current_anchor_row]
        [game_state.current_anchor_col]);
    if (letter) {
        go_on(pos, letter, word, rack, next_arc(arc, letter), arc, spaces);
    } else if (letters_remain(rack)) {
        /*
         * TODO: for each letter ALLOWED ON THIS SQUARE, not just all
         * letters.
         */
        // For all letters, except the blank.
        for (i = 0; i < game_state.num_distinct_letters - 1; i++) {
            if (rack[i] > 0) {
                #ifdef DEBUG_
                print_spaces(spaces);
                printf("%d %cs\n", rack[i], i + 'A');
                #endif
                // Letter (i + 'A') is on this rack. Temporarily remove it.
                rack[i]--;
                go_on(pos, i + 'A', word, rack, next_arc(arc, i + 'A'),
                      arc, spaces + 1);
                // Re-add letter.
                rack[i]++;
            }
        }
        // Check if there is a blank.
        if (rack[blank_position] > 0) {
            // For each blank
            for (k = 0; k < game_state.num_distinct_letters; k++) {
                /**
                 * TODO: For each letter the blank could be ALLOWED
                 * ON THIS SQUARE.
                 */
                rack[blank_position]--;
                go_on(pos, k + 'A', word, rack, next_arc(arc, k + 'A'),
                      arc, spaces + 1);
                rack[blank_position]++;
            }
        }
    }
}
Esempio n. 23
0
int check_option( char argv, char letter_begin, char letter_end ){

	if ( is_letter( argv ) != 0 ){
	  printf("[!!]ERROR %c is not a letter.\n", argv );
	  return EXIT_FAILURE;
	}
	else{
		if ( is_letter_between( argv, letter_begin, letter_end ) != 0 ){
			return EXIT_FAILURE;
		}
	}

	return EXIT_SUCCESS;
}
Esempio n. 24
0
int Lex_analyzer::getLiterType(QChar c){
    if(is_letter(c))
        return 1;
    else if(is_digit(c))
        return 2;
    else if(is_one_lit_sep(c))
        return 3;
    else if(is_begin_sep(c))
        return 4;
    else if(is_end_sep(c))
        return 5;
    else if(is_missed_sym(c))
        return 6;
    else return 0;
}
Esempio n. 25
0
void
smart_font_rep::advance (string s, int& pos, string& r, int& nr) {
  int* chv= sm->chv;
  hashmap<string,int>& cht (sm->cht);
  int start= pos;
  nr= -1;
  while (pos < N(s)) {
    if (s[pos] != '<') {
      int c= (int) (unsigned char) s[pos];
      int next= chv[c];
      if (math_kind != 0 && math_kind != 2 && is_letter (c) &&
          (pos == 0 || !is_letter (s[pos-1])) &&
          (pos+1 == N(s) || !is_letter (s[pos+1])))
        next= italic_nr;
      else if (chv[c] == -1) next= resolve (s (pos, pos+1));
      if (next == nr) pos++;
      else if (nr == -1) { pos++; nr= next; }
      else break;
    }
    else {
      int end= pos;
      tm_char_forwards (s, end);
      int next= cht[s (pos, end)];
      if (next == -1) next= resolve (s (pos, end));
      if (next == nr) pos= end;
      else if (nr == -1) { pos= end; nr= next; }
      else break;
    }
  }
  r= s (start, pos);
  if (nr < 0) return;
  if (N(fn) <= nr || is_nil (fn[nr])) initialize_font (nr);
  if (sm->fn_rewr[nr] != REWRITE_NONE)
    r= rewrite (r, sm->fn_rewr[nr]);
  //cout << "Got " << r << " in " << fn[nr]->res_name << "\n";
}
Esempio n. 26
0
char * dec_token(struct dec * dec)
{
    size_t i;
    char x;

    i = 0;
    for (;;) {
        dec->token[i] = dec_read(dec);
        if (is_letter(dec->token[i])) {
            break;
        } else if (dec->token[i] == 0) {
            return NULL;
        }
    }
    i = 1;
    for (;;) {
        dec->token[i] = dec_read(dec);
        if (!is_letter(dec->token[i])) {
            dec->token[i] = (char)0;
            return dec->token;
        }
        ++i;
    }
}
Esempio n. 27
0
void compute_statistics(U_FILE *f,vector_ptr* tokens,Alphabet* alph,
		                int SENTENCES,int TOKENS_TOTAL,int WORDS_TOTAL,int DIGITS_TOTAL) {
int DIFFERENT_DIGITS=0;
int DIFFERENT_WORDS=0;
for (int i=0;i<tokens->nbelems;i++) {
   unichar* foo=(unichar*)tokens->tab[i];
   if (u_strlen(foo)==1) {
      if (foo[0]>='0' && foo[0]<='9') DIFFERENT_DIGITS++;
   }
   if (is_letter(foo[0],alph)) DIFFERENT_WORDS++;
}
u_fprintf(f,"%d sentence delimiter%s, %d (%d diff) token%s, %d (%d) simple form%s, %d (%d) digit%s\n",
		SENTENCES,(SENTENCES>1)?"s":"",TOKENS_TOTAL,tokens->nbelems,(TOKENS_TOTAL>1)?"s":"",WORDS_TOTAL,
		DIFFERENT_WORDS,(WORDS_TOTAL>1)?"s":"",DIGITS_TOTAL,DIFFERENT_DIGITS,(DIGITS_TOTAL>1)?"s":"");
}
Esempio n. 28
0
/**
 * Returns 1 if the given sequence can be considered as a simple word;
 * 0 otherwise.
 *
 * NOTE: with such a definition, a single char that is not a letter is not a simple word
 */
int is_a_simple_word(const unichar* sequence,TokenizationPolicy tokenization_policy,const Alphabet* alphabet) {
int i;
i=0;
if (tokenization_policy==CHAR_BY_CHAR_TOKENIZATION && u_strlen(sequence)>1) {
   /* In a char by char mode, a string longer than 1 cannot be a simple word */
   return 0;
}
/* Here, we are a bit parano since '\0' is not supposed to be in the alphabet */
while (sequence[i]!='\0' && is_letter(sequence[i],alphabet)) {
   i++;
}
if (sequence[i]=='\0') {
   return 1;
}
return 0;
}
Esempio n. 29
0
byte makeInt(int scan_code) 
{
	switch(scan_code) 
	{
		case RIGHT_SHIFT_MAKE:
			shiftActivated = 1;
			return 0;
		case LEFT_SHIFT_MAKE:
			shiftActivated = 1;
			return 0;
		case CAPS_LOCK:
			capsLockActivated = !capsLockActivated;
			return 0;
		case ALT_MAKE:
			altActivated = 1;
			return 0;
		case ACCENT_MAKE:
			if (current_keyboard == 1)
			{
				accent = 1;
				return 0;
			}
	}
	if (altActivated && 
		scan_code >= 0x02 && scan_code < 0x02 + MAX_SHELLS)
		changing_shell = 1;  
	if (accent && current_keyboard == 1)
	{
		if (shiftActivated ^ capsLockActivated)
		{
			accent = 0;			
		} else if (is_vowel(scan_code)) {
			accent = 0;
			return accent_vowel(scan_code);
		} else {
			write_buffer(keyboards[current_keyboard][ACCENT_MAKE][0]);
			accent = 0;
		}
	}
	if (is_letter(scan_code))
	{
		return keyboards[current_keyboard]
					[scan_code][shiftActivated ^ capsLockActivated];
	}
	return keyboards[current_keyboard][scan_code][shiftActivated];
}
Esempio n. 30
0
/**
 * Validate whether the string is a legal NCName.
 * Refer http://www.w3.org/TR/REC-xml-names/ for detail.
 *
 * \param str  The name to validate
 * \return true if ::name is valid, false otherwise.
 */
bool _dom_validate_ncname(dom_string *name)
{
	uint32_t ch;
	size_t clen, slen;
	parserutils_error err;
	const uint8_t *s;

	if (name == NULL)
		return false;

	slen = dom_string_length(name);
	if (slen == 0)
		return false;

	s = (const uint8_t *) dom_string_data(name);
	slen = dom_string_byte_length(name);
	
	err = parserutils_charset_utf8_to_ucs4(s, slen, &ch, &clen);
	if (err != PARSERUTILS_OK) {
		return false;
	}
	
	if (is_letter(ch) == false && ch != (uint32_t) '_')
		return false;
	
	s += clen;
	slen -= clen;
	
	while (slen > 0) {
		err = parserutils_charset_utf8_to_ucs4(s, slen, &ch, &clen);
		if (err != PARSERUTILS_OK) {
			return false;
		}

		if (is_name_char(ch) == false)
			return false;

		if (ch == (uint32_t) ':')
			return false;

		s += clen;
		slen -= clen;
	}

	return true;
}