Fx23
Text scanner, available in Node.js, C# and Objective-C.
Installation:
# yarn yarn add fx23# npm npm install fx23 --save
Run tests:
# yarn yarn test# npm npm test
API
Fx23StringReader Class (Core Members)
Properties
collectLineInfo
counts lineIndex and columnIndex during each read operation, default is false.index
the index position of current character.columnIndex
zero-based column number of current character at current line.lineIndex
zero-based line number of current character.visibleIndex
the index position of current character without newline characters.length
total length of the string.
Methods
hasNext
returns false if no more character to read.peek
returns the next character without moving the internal index.next
returns the next character and move the internal index forward.mark
marks a flag at current position.collect
returns a sub-string from last marked position to current position.nextOverride
implementated by subclass.peekOverride
implementated by subclass.
Fx23StringReader Class (Extension Members)
These methods are built onto the core members.
Methods
collectWhile
moves forward while condition is true, and returns the string scanned.skipWhile
moves forward while condition is true.moveToContent
moves to next non-whitespace character.skipLine
moves to next line.collectLine
moves to next line and returns current line.
Example
// ES6+const Fx23StringReader = ; // the string we need to scanconst str = ' abcdef\r\na b c\nMgen123abc'; // initialize the readerconst reader = str;// counts lineIndex and columnIndex during each read operationreadercollectLineInfo = true; console;reader;;/* Reader position: " abcdef\r\na b c\nMgen123abc" ---|------ - ------ ---------- Output: Move to content Current char: 'a' Line: 1 Column: 4 Index(without newline): 3 Index: 3 */ console;console;;/* Reader position: " abcdef\r\na b c\nMgen123abc" ---====|-- - ------ ---------- Output: Read until 'e' Result -> abcd Current char: "e" Line: 1 Column: 8 Index(without newline): 7 Index: 7 */ console;console;;/* Reader position: " abcdef\r\na b c\nMgen123abc" -------==- - |----- ---------- Output: Get remaining characters in current line Result -> ef Current char: 'a' Line: 2 Column: 1 Index(without newline): 9 Index: 11 */ console;reader;;/* Reader position: " abcdef\r\na b c\nMgen123abc" ---------- - ------ |--------- Output: Skip the whole line Current char: 'M' Line: 3 Column: 1 Index(without newline): 14 Index: 17 */ console;reader;;/* Reader position: " abcdef\r\na b c\nMgen123abc" ---------- - ------ ----|----- Output: Skip to first number Current char: '1' Line: 3 Column: 5 Index(without newline): 18 Index: 21 */ console;console;;/* Reader position: " abcdef\r\na b c\nMgen123abc" ---------------------------|-- Output: Read all numbers 123 Current char: 'a' Line: 3 Column: 8 Index(without newline): 21 Index: 24 */ console;reader;while reader readernext;console;/* Reader position: " abcdef\r\na b c\nMgen123abc" ---------------------------=== Output: Result -> abc */ { var curChar; if reader curChar = reader; else curChar = 'End of string'; console;}