nextWord

Returns the next word in the range passed as argument.

  1. auto nextWord(ref Range range, T charTester)
    nextWord
    (
    Range
    T
    bool until = false
    )
    (
    ref Range range
    ,
    )
    if (
    isInputRange!Range &&
    isSomeChar!(ElementType!Range)
    &&
    )
  2. auto nextWord(ref Range range)

Parameters

range
Type: Range

A character input range. The range is consumed for each word.

charTester
Type: T

Defines the valid characters to make a word.

Return Value

Type: auto

A string containing the word. If the result length is null then the range parameter has not been consumed.

Examples

1 auto cs1 = "azertyuiopqsdfghjklmwxcvbn";
2 auto cs2 = " \r\n\t";
3 auto cs3 = CharRange('a','z');
4 bool[dchar] cs4 = ['\r':true, '\n': true, '\t':true, ' ':true ];
5 auto src1 = "az er
6 ty";
7 auto src2 = "az er
8 ty";
9 
10 auto w1 = nextWord(src1, cs1);
11 assert(w1 == "az");
12 nextWord(src1, cs2);
13 auto w2 = nextWord(src1, cs1);
14 assert(w2 == "er");
15 nextWord(src1, cs2);
16 auto w3 = nextWord(src1, cs1);
17 assert(w3 == "ty");
18 nextWord(src1, cs2);
19 
20 auto w11 = nextWord(src2, cs3);
21 assert(w11 == "az");
22 nextWord(src2, cs4);
23 auto w22 = nextWord(src2, cs3);
24 assert(w22 == "er");
25 nextWord(src2, cs4);
26 import std.ascii: isAlpha, isDigit;
27 assert(nextWord(src2, &isDigit) == "");
28 auto w33 = nextWord(src2, &isAlpha);
29 assert(w33 == "ty");

Meta