vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.8k stars 2.17k forks source link

is_western_chars_only in utf8_util.v? #19777

Open verulian opened 1 year ago

verulian commented 1 year ago

Describe the feature

I noticed that @JalonSolov made some cleanup changes to https://github.com/vlang/v/blob/master/vlib/encoding/utf8/utf8_util.v about western-only encoding. Am I missing the logic here or are we missing a function like "is_western_chars_only" that would test a string to ensure that it is western only before performing operations? Initially hwen I look at this it seems the programmer needs to know if it is or should be this only, but it might be easier if this is used many times to have a simple test to ensure westernness of the string before performing operations.

Use Case

If western-only operations are used multiple times it would be better to have a test available to ensure westernness of the variable in question vs depending on developer awareness. If it is a one-off this might not make sense, but if there are many it might make sense.

Proposed Solution

Parse/test string to ensure westernness or non-westernness.

Other Information

No response

Acknowledgements

Version used

current

Environment details (OS name and version, etc.)

n/a

[!NOTE] You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote. Other reactions and those to comments will not be taken into account.

JalonSolov commented 1 year ago

All I changed in that section was the comment style. The code there is the same as it has been for a long time.

The comments are somewhat misleading... "western" just means ASCII codes, and the first 128 UTF-8 codes == ASCII codes.

I can't think of a reason why we would need an "is_western_chars_only" check.

verulian commented 1 year ago

I guess thinking of just the speed diff betwixt western and !western only for large iteration scenarios might be useful but I will close if this is nonsensical which seems you are indicating.

JalonSolov commented 1 year ago

I don't know. If you have a valid use-case, please show it. All I said was I can't think of one.