length, substr, index and . count bytes, not characters, in a UTF-8 locale

Aberta
#151 1 comentário 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
48/100
Tipo de issue
Funcionalidade
Clareza
Razoavelmente clara
Status de atividade
Ativa
Stack de tecnologia
rust
Domínio
backend

Direção de pesquisa

Start with the byte-based string functions in interpreter/src/builtins.rs and the locale handling in lexer/src/locale_encoding.rs; then trace how regular expressions handle character positions. Check the existing tests for length, substr, index, and regex matching. Done means UTF-8 locales count characters and preserve valid UTF-8, while LC_ALL=C retains byte behavior.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

bug

In a UTF-8 locale, string functions and regexps treat each byte as a character:

$ echo héllo | awk '{print length($0), index($0, "l"), substr($0, 2, 1)}'
6 4 �
$ echo héllo | awk '/^.....$/ {print "five"}'
$ echo héllo | awk '{print toupper($0)}'
HéLLO

gawk 5.3.2 prints 5 3 é, five and HÉLLO. POSIX defines these in characters, and substr here cuts é in half, so the output is not valid UTF-8. With LC_ALL=C, gawk counts bytes too (6).

length, substr, index work on bytes in interpreter/src/builtins.rs, and the regex is byte based. The lexer already reads the locale for \u escapes (lexer/src/locale_encoding.rs), so the locale is known.

Is character semantics in a UTF-8 locale planned? I can send a PR for the string built-ins if you want it.

Checked on main 67e0816, LANG=en_US.UTF-8.

Linguagem predominante
Rust
Estrelas
31
Forks
13
Merge médio
23h 42min
PRs com merge (30d)
29

Preparar o ambiente

Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de uutils/awk

Todas as issues de uutils/awk

Issues semelhantes

Mais issues de Rust

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.