1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vlib: remove ustring usage (#10618)

This commit is contained in:
Daniel Däschle
2021-06-30 21:30:28 +02:00
committed by GitHub
parent 9d02ca51d1
commit 3881e97a40
14 changed files with 86 additions and 80 deletions

View File

@ -17,58 +17,58 @@ import os
// read_line_utf8 blocks execution in a loop and awaits user input
// characters from a terminal until `EOF` or `Enter` key is encountered
// in the input stream.
// read_line_utf8 returns the complete input line as an UTF-8 encoded `ustring` or
// read_line_utf8 returns the complete input line as an UTF-8 encoded `[]rune` or
// an error if the line is empty.
// The `prompt` `string` is output as a prefix text for the input capturing.
// read_line_utf8 is the main method of the `readline` module and `Readline` struct.
pub fn (mut r Readline) read_line_utf8(prompt string) ?ustring {
r.current = ''.ustring()
pub fn (mut r Readline) read_line_utf8(prompt string) ?[]rune {
r.current = []rune{}
r.cursor = 0
r.prompt = prompt
r.search_index = 0
if r.previous_lines.len <= 1 {
r.previous_lines << ''.ustring()
r.previous_lines << ''.ustring()
r.previous_lines << []rune{}
r.previous_lines << []rune{}
} else {
r.previous_lines[0] = ''.ustring()
r.previous_lines[0] = []rune{}
}
print(r.prompt)
line := os.get_raw_line()
if line.len >= 0 {
r.current = line.ustring()
r.current = line.runes()
}
r.previous_lines[0] = ''.ustring()
r.previous_lines[0] = []rune{}
r.search_index = 0
if r.current.s == '' {
if r.current.len == 0 {
return error('empty line')
}
return r.current
}
// read_line does the same as `read_line_utf8` but returns user input as a `string`.
// (As opposed to `ustring` returned by `read_line_utf8`).
// (As opposed to `[]rune` returned by `read_line_utf8`).
pub fn (mut r Readline) read_line(prompt string) ?string {
s := r.read_line_utf8(prompt) ?
return s.s
return s.string()
}
// read_line_utf8 blocks execution in a loop and awaits user input
// characters from a terminal until `EOF` or `Enter` key is encountered
// in the input stream.
// read_line_utf8 returns the complete input line as an UTF-8 encoded `ustring` or
// read_line_utf8 returns the complete input line as an UTF-8 encoded `[]rune` or
// an error if the line is empty.
// The `prompt` `string` is output as a prefix text for the input capturing.
// read_line_utf8 is the main method of the `readline` module and `Readline` struct.
// NOTE that this version of `read_line_utf8` is a standalone function without
// persistent functionalities (e.g. history).
pub fn read_line_utf8(prompt string) ?ustring {
pub fn read_line_utf8(prompt string) ?[]rune {
mut r := Readline{}
s := r.read_line_utf8(prompt) ?
return s
}
// read_line does the same as `read_line_utf8` but returns user input as a `string`.
// (As opposed to `ustring` as returned by `read_line_utf8`).
// (As opposed to `[]rune` as returned by `read_line_utf8`).
// NOTE that this version of `read_line` is a standalone function without
// persistent functionalities (e.g. history).
pub fn read_line(prompt string) ?string {