char string library. There is a character string splitting function.
CharUtil.cpp@1:fc299d8c1c7e, 2017-12-03 (annotated)
- Committer:
- tichise
- Date:
- Sun Dec 03 06:19:23 2017 +0000
- Revision:
- 1:fc299d8c1c7e
- Parent:
- StringUtil.cpp@0:c6bf0554e2f3
- Child:
- 2:dbd6f2a04946
change name
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tichise | 1:fc299d8c1c7e | 1 | #include "CharUtil.h" |
tichise | 0:c6bf0554e2f3 | 2 | #include "mbed.h" |
tichise | 0:c6bf0554e2f3 | 3 | |
tichise | 0:c6bf0554e2f3 | 4 | #define MAXITEM 20 // 数字が大きすぎるとメモリーオーバーエラーがでる |
tichise | 0:c6bf0554e2f3 | 5 | |
tichise | 1:fc299d8c1c7e | 6 | CharUtil::CharUtil() { |
tichise | 0:c6bf0554e2f3 | 7 | } |
tichise | 0:c6bf0554e2f3 | 8 | |
tichise | 1:fc299d8c1c7e | 9 | int CharUtil::split(char *base, const char *delim, char *outlist[]){ |
tichise | 1:fc299d8c1c7e | 10 | char *token; |
tichise | 0:c6bf0554e2f3 | 11 | int cnt = 0; |
tichise | 0:c6bf0554e2f3 | 12 | |
tichise | 1:fc299d8c1c7e | 13 | token = strtok(base, delim); |
tichise | 0:c6bf0554e2f3 | 14 | |
tichise | 1:fc299d8c1c7e | 15 | while(token != NULL && cnt < MAXITEM) { |
tichise | 1:fc299d8c1c7e | 16 | outlist[cnt++] = token; |
tichise | 1:fc299d8c1c7e | 17 | token = strtok(NULL, delim); |
tichise | 0:c6bf0554e2f3 | 18 | } |
tichise | 0:c6bf0554e2f3 | 19 | |
tichise | 0:c6bf0554e2f3 | 20 | return cnt; |
tichise | 0:c6bf0554e2f3 | 21 | } |