void write_split(char **split, char *str, char *charset) { int i; int j; int k; int word; word = 0; i = 0; while (str[i] != '\0') { if (char_is_separator(str[i], charset) == 1) i++; else { j = 0; while (char_is_separator(str[i + j], charset) == 0) j++; split[word] = (char*)malloc(sizeof(char) * (j + 1)); write_word(split[word], str + i, charset); i += j; word++; } } }
void write_matrix(char **matrix, char *str) { int i; int j; int word; i = 0; word = 0; while (str[i] != '\0') { if (char_is_separator(str[i]) == 0) { j = 0; while (char_is_separator(str[i + j]) == 0) j++; matrix[word] = (char*)malloc(sizeof(char) * (j + 1)); write_word((matrix[word]), (str + i)); word++; i += j; } else i++; } matrix[word] = (char*)malloc(sizeof(char) * 1); matrix[word] = 0; }
int count_words(char *str, char *charset) { int i; int words; words = 0; i = 0; while (str[i] != '\0') { if (char_is_separator(str[i + 1], charset) == 1 && char_is_separator(str[i], charset) == 0) words++; i++; } return (words); }
void write_word(char *dest, char *from, char *charset) { int i; i = 0; while (char_is_separator(from[i], charset) == 0) { dest[i] = from[i]; i++; } dest[i] = '\0'; }
void write_word(char *word, char *str) { int i; i = 0; while (char_is_separator(str[i]) == 0) { word[i] = str[i]; i++; } word[i] = '\0'; }
Token *token_from_lexeme(Token *lexeme) { char *word = string_value(lexeme_value(lexeme)); void *value = NULL; char first_char = word[0]; if ( char_is_line_end(first_char) ) { token_type(lexeme) = FX_TOKEN_LINE_END; string_free(token_value(lexeme)); } else if ( char_is_statement_end(first_char) ) { token_type(lexeme) = FX_TOKEN_STATEMENT_END; string_free(token_value(lexeme)); } else if ( char_is_method_selector(first_char) ) { token_type(lexeme) = FX_TOKEN_ATTRIBUTE_SELECTOR; string_free(token_value(lexeme)); } else if ( char_opens_group(first_char) ) { token_type(lexeme) = FX_TOKEN_GROUP_START; string_free(token_value(lexeme)); } else if ( char_closes_group(first_char) ) { token_type(lexeme) = FX_TOKEN_GROUP_END; string_free(token_value(lexeme)); } else if ( char_is_separator(first_char) ) { token_type(lexeme) = FX_TOKEN_COMMA; string_free(token_value(lexeme)); } else if ( char_opens_block(first_char) ) { token_type(lexeme) = FX_TOKEN_BLOCK_START; string_free(token_value(lexeme)); } else if ( char_closes_block(first_char) ) { token_type(lexeme) = FX_TOKEN_BLOCK_END; string_free(token_value(lexeme)); } else if ( char_is_setter(first_char) && lexeme_length(lexeme) == 1 ) { token_type(lexeme) = FX_TOKEN_LOCAL_SETTER; string_free(token_value(lexeme)); } else if ( char_is_colon(first_char) && lexeme_length(lexeme) == 1 ) { token_type(lexeme) = FX_TOKEN_ATTRIBUTE_SETTER; string_free(token_value(lexeme)); } else if ( char_is_deferred_arg(first_char) && lexeme_length(lexeme) == 1 ) { token_type(lexeme) = FX_TOKEN_DEFERRED_ARGUMENT; string_free(token_value(lexeme)); } else if ( word_is_block_declaration(word) ) { token_type(lexeme) = FX_TOKEN_BLOCK_DECLARATION; string_free(token_value(lexeme)); } else if ( char_is_regex_bookend(first_char) ) { token_type(lexeme) = FX_TOKEN_REGEX; } else if ( char_is_string_bookend(first_char) ) { token_type(lexeme) = FX_TOKEN_STRING; word[lexeme_length(lexeme) - 1] = '\0'; // shortening string contents to remove the quotation marks value = String_create((word+1)); check(value, "token string value is NULL"); string_free(token_value(lexeme)); token_value(lexeme) = value; } else if ( lexed_word_is_number(word) ) { token_type(lexeme) = FX_TOKEN_NUMBER; value = Number_create(word); check(value, "token number is NULL"); string_free(token_value(lexeme)); token_value(lexeme) = value; } else if ( char_is_capitalized(first_char) ) { token_type(lexeme) = FX_TOKEN_GLOBAL_ID; } else if ( char_is_colon(first_char) ) { token_type(lexeme) = FX_TOKEN_ATOM; value = String_create((word+1)); check(value, "token string value is NULL"); string_free(token_value(lexeme)); token_value(lexeme) = value; } else { token_type(lexeme) = FX_TOKEN_ID; } return lexeme; error: return NULL; }