KHLALA-Gh / The-Book

A Simple desktop application for reading books.
https://the-book-red.vercel.app
MIT License
0 stars 0 forks source link

Invalid name when creating a book with non english alphabets #2

Closed KHLALA-Gh closed 5 months ago

KHLALA-Gh commented 5 months ago

An error shown when creating a new book with characters like "السلام عليكم " or "Привет ребята".

image

When checking in the app resources directory, i found the book directory created containing all the files. But the book does not appear in my library, which may mean the book is not inserted in the database.

KHLALA-Gh commented 5 months ago

Well this happening because the book name should be less than 17 characters, and to make sure the name is less than 17 chars we use the len() function in go. But the problem is that the len() function returns the number of bytes not the number of runes. So to get the number of runes we can use instead utf8.RuneCountInString(str). You can see https://github.com/golang/go/issues/22127 for more info.