Mercurial > hg > Applications > Grep
diff c/regexParser/word.cc @ 118:31b0ba0050fa testcode
text
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 26 Nov 2015 17:19:00 +0900 |
parents | c/regexParser/word.c@166136236891 |
children | 5d29b6a1b50f |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c/regexParser/word.cc Thu Nov 26 17:19:00 2015 +0900 @@ -0,0 +1,36 @@ +#include <ctype.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include "word.h" + +WordPtr getWord(unsigned char *string) { + + WordPtr w = (WordPtr)malloc(sizeof(Word)); + + int i = 0; + while (isalnum(string[i])) { + i++; + } + + int allocateWordSize, wordLength; + + unsigned char *word = NULL; + if (string[i] == '*') { + wordLength = i-1; + allocateWordSize = i; + word = (unsigned char*)malloc(sizeof(unsigned char)*allocateWordSize); + strncpy((char*)word, (char*)string, allocateWordSize); + word[allocateWordSize-1] = '\0'; + } else { + wordLength = i; + allocateWordSize = i+1; + word = (unsigned char*)malloc(sizeof(unsigned char)*allocateWordSize); + strncpy((char*)word, (char*)string, allocateWordSize); + word[allocateWordSize] = '\0'; + } + + w->word = word; + w->length = wordLength; + return w; +}