count chars, not bytes

pull/14/head
chris west 4 years ago
parent 85998aba06
commit 6a429c8a86

@ -111,12 +111,11 @@ To enable just TLS support, or just Tor support, use `--features`:
## todo
- [ ] don't create new strings for every Line
- [ ] catch SIGWINCH
- [ ] disable ctrl-c outside of raw mode (telnet)
## bugs
- [ ] ctrl-c while telneting kills phetch
- [ ] unknown keypress: [ during status messages
- [ ] new status doesn't replace old (download complete -> copy url)

@ -75,7 +75,7 @@ impl Line {
/// Returns the text field of this line, given a raw Gopher response.
/// The same Line must always be used with the same Gopher response.
pub fn text<'a>(&self, raw: &'a str) -> &'a str {
if raw.len() >= self.text_end && self.start < self.text_end {
if self.start < self.text_end {
&raw[self.start + 1..self.text_end]
} else {
""
@ -820,7 +820,7 @@ impl Menu {
let s = self
.input
.chars()
.take(self.input.len())
.take(self.input.chars().count())
.collect::<String>();
if let Ok(num) = s.parse::<usize>() {
if num > 0 && num <= self.links.len() {
@ -896,7 +896,7 @@ pub fn parse_line(start: usize, raw: &str) -> Option<Line> {
}
let line = &raw[start..];
let end = line.find('\n').unwrap_or_else(|| line.len()) + start;
let end = line.find('\n').unwrap_or_else(|| line.chars().count()) + start;
let line = &raw[start..end]; // constrain \t search
let text_end = if let Some(i) = line.find('\t') {
i + start

@ -166,8 +166,9 @@ impl Text {
let mut longest = 0;
for line in response.split_terminator('\n') {
lines += 1;
if line.len() > longest {
longest = line.len();
let count = line.chars().count();
if count > longest {
longest = count;
}
}

Loading…
Cancel
Save