OSDN Git Service

Merge pull request #3569 from sikabane-works/release/3.0.0.88-alpha
[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 int16_t tokenize_whitespace(char *buf, int16_t num, char **tokens)
26 {
27     int16_t k = 0;
28     char *s = buf;
29
30     while (k < num) {
31         char *t;
32         for (; *s && iswspace(*s); ++s) { /* loop */
33             ;
34         }
35
36         if (!*s) {
37             break;
38         }
39
40         for (t = s; *t && !iswspace(*t); ++t) { /* loop */
41             ;
42         }
43
44         if (*t) {
45             *t++ = '\0';
46         }
47
48         tokens[k++] = s;
49         s = t;
50     }
51
52     return k;
53 }