Skip to content

feat: join strings with a conjunction in a handful of languages - #14

Merged
meowgorithm merged 1 commit into
mainfrom
join
Oct 25, 2023
Merged

feat: join strings with a conjunction in a handful of languages#14
meowgorithm merged 1 commit into
mainfrom
join

Conversation

@meowgorithm

@meowgorithm meowgorithm commented Oct 25, 2023

Copy link
Copy Markdown
Member

At last, join strings in the way they would be read by a human being. For example, []string{"cheese", "beans", "jalapeños"} can become "cheese, beans and jalapeños", with a flick of the wrist.

import str "gitub.com/charmbracelet/x/exp/strings"

x := []string{"eins", "zwei", "drei"}
s := str.SpokenLanguageJoin(x, str.DE)
fmt.Println(s) // eins, zwei und drei

English users can also opt into to the Oxford Comma with the hot EnglishJoin function:

x := []string{"meow", "purr", "raow"}
s := str.EnglishJoin(x, true)
fmt.Println(s) // meow, purr, and raow

The following languages are supported:

  • German (DE)
  • Danish (DK)
  • English (EN)
  • Spanish (ES)
  • French (FR)
  • Italian (IT)
  • Norwegian (NO)
  • Portuguese (PT)
  • Swedish (SE)

@meowgorithm
meowgorithm merged commit 6eef475 into main Oct 25, 2023
@meowgorithm
meowgorithm deleted the join branch October 25, 2023 02:00
@caarlos0

Copy link
Copy Markdown
Contributor

LOVE THIS!

tzengyuxio added a commit to tzengyuxio/x that referenced this pull request Apr 9, 2026
Wide characters (CJK ideographs, fullwidth chars) can be broken between
any two characters per Unicode line breaking rules (UAX charmbracelet#14). Previously,
consecutive wide characters were accumulated into the word buffer and
treated as a single long "word", causing suboptimal wrapping:

- Mixed CJK/Latin text like "vault 不只是記事本" would push the entire
  CJK sequence to the next line instead of filling the current line
- CJK text only got hard-wrapped when the word exceeded the limit,
  wasting space at the end of lines

Now wide characters (width > 1) are written directly to the output
buffer, allowing line breaks between any two wide characters. This
produces more natural wrapping for CJK text while preserving word
boundaries for narrow (Latin) characters.
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