OSDN Git Service

Merge pull request #1058 from sikabane-works/feature/enum-virtue
[hengbandforosx/hengbandosx.git] / src / main-win / main-win-tokenizer.cpp
1 /*!
2  * @file main-win-tokenizer.cpp
3  * @brief Windows版固有実装(トークン分割)
4  */
5
6 #include "main-win/main-win-tokenizer.h"
7
8 #include <ctype.h>
9
10 /*
11  * - Taken from files.c.
12  *
13  * Extract "tokens" from a buffer
14  *
15  * This function uses "whitespace" as delimiters, and treats any amount of
16  * whitespace as a single delimiter.  We will never return any empty tokens.
17  * When given an empty buffer, or a buffer containing only "whitespace", we
18  * will return no tokens.  We will never extract more than "num" tokens.
19  *
20  * By running a token through the "text_to_ascii()" function, you can allow
21  * that token to include (encoded) whitespace, using "\s" to encode spaces.
22  *
23  * We save pointers to the tokens in "tokens", and return the number found.
24  */
25 s16b tokenize_whitespace(char *buf, s16b num, char **tokens)
26 {
27     s16b k = 0;
28     char *s = buf;
29
30     while (k < num) {
31         char *t;
32         for (; *s && iswspace(*s); ++s) /* loop */
33             ;
34
35         if (!*s)
36             break;
37
38         for (t = s; *t && !iswspace(*t); ++t) /* loop */
39             ;
40
41         if (*t)
42             *t++ = '\0';
43
44         tokens[k++] = s;
45         s = t;
46     }
47
48     return k;
49 }