Mercurial > hg > Applications > Grep
annotate 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 |
rev | line source |
---|---|
113 | 1 #include <ctype.h> |
2 #include <string.h> | |
3 #include <stdio.h> | |
4 #include <stdlib.h> | |
117
166136236891
add header files
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
115
diff
changeset
|
5 #include "word.h" |
113 | 6 |
118 | 7 WordPtr getWord(unsigned char *string) { |
8 | |
9 WordPtr w = (WordPtr)malloc(sizeof(Word)); | |
10 | |
11 int i = 0; | |
12 while (isalnum(string[i])) { | |
13 i++; | |
113 | 14 } |
15 | |
118 | 16 int allocateWordSize, wordLength; |
17 | |
18 unsigned char *word = NULL; | |
19 if (string[i] == '*') { | |
20 wordLength = i-1; | |
21 allocateWordSize = i; | |
22 word = (unsigned char*)malloc(sizeof(unsigned char)*allocateWordSize); | |
23 strncpy((char*)word, (char*)string, allocateWordSize); | |
24 word[allocateWordSize-1] = '\0'; | |
25 } else { | |
26 wordLength = i; | |
27 allocateWordSize = i+1; | |
28 word = (unsigned char*)malloc(sizeof(unsigned char)*allocateWordSize); | |
29 strncpy((char*)word, (char*)string, allocateWordSize); | |
30 word[allocateWordSize] = '\0'; | |
31 } | |
32 | |
33 w->word = word; | |
34 w->length = wordLength; | |
35 return w; | |
113 | 36 } |