Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strings.textscanner: add rune mode support; add next_line() , read_until(), substr() funcs #23874

Closed

Conversation

kbkpbot
Copy link
Contributor

@kbkpbot kbkpbot commented Mar 6, 2025

Introduce force_rune_mode params to the new(input string, config TextScannerConfig) and this will help scan runes instead of bytes of a input string.

@[params]
pub struct TextScannerConfig {
pub mut:
	force_rune_mode bool
}

// new returns a stack allocated instance of TextScanner.
pub fn new(input string, config TextScannerConfig) TextScanner

// next_line advances the scanner’s position to the start of
// the next line, and return the line.
// Returns true if successful, or false if the end of the input
// is reached.

pub fn (mut ss TextScanner) next_line() (string, bool) 

// read_until reads characters from the current scanning position
// until a delimiter (from the provided string `delimiters`) is encountered.
// The returned string includes all characters from the starting
// position up to (but ​not​ including) the first encountered
// delimiter. The scanner's position is advanced to the character
// immediately after the delimiter (or to the end of the input if
// no delimiter is found).

pub fn (mut ss TextScanner) read_until(delimiters string) !string

// substr return a sub string of input string from start to end.
pub fn (mut ss TextScanner) substr(start int, end int) string 

Copy link

Connected to Huly®: V_0.6-22278

@kbkpbot kbkpbot changed the title strings.textscanner: add next_line() and read_until() funcs strings.textscanner: add rune mode support; add next_line() and read_until() funcs Mar 7, 2025
@kbkpbot kbkpbot changed the title strings.textscanner: add rune mode support; add next_line() and read_until() funcs strings.textscanner: add rune mode support; add next_line() , read_until(), substr() funcs Mar 7, 2025
@spytheman
Copy link
Member

May be there is a misunderstanding - I do not want rune mode support, and if you do want it, you can just write your own scanner module, outside of vlib's strings. Supporting a rune mode only complicates and slows down the scanner.

My comment was just to point out, that you can pass a string for the separators, which is more compact.

@spytheman spytheman closed this Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants