Opened 10 years ago

Closed 10 years ago

#7788 closed Patches (invalid)

locale_data::parse could be simplified

Reported by: 166291@… Owned by: Artyom Beilis
Milestone: To Be Determined Component: locale
Version: Boost Development Trunk Severity: Optimization
Keywords: Cc:

Description

(If there's another way to submit patches, please do tell. :))

So I've written this patch that simplifies locale_data::parse greatly.

Pitfalls:

It does allow invalid locale names like (en.UTF-8@eruo_US) to be parsed in to its correct components, but since it's an internal API that doesn't seem to matter.

It's now case-sensitive. Which required a change in the unit tests to pass. It'd be trivial to fix this (one line of code when appending the character), but I personally desire this behaviour as it means I can get out what I put in to Boost.Locale via my code. It doesn't seem to break anything and the unit tests and/or documentation for the most part don't indicate it's important.

Attachments (2)

locale_data.patch (5.6 KB ) - added by anonymous 10 years ago.
new_patch.patch (4.6 KB ) - added by 166291@… 10 years ago.

Download all attachments as: .zip

Change History (4)

by anonymous, 10 years ago

Attachment: locale_data.patch added

by 166291@…, 10 years ago

Attachment: new_patch.patch added

comment:1 by 166291@…, 10 years ago

I added another patch which eliminates both the pitfalls, and is a bit more complex but still less redundant than the original code.

I would like to know why case sensitivity is a factor though.

comment:2 by Artyom Beilis, 10 years ago

Resolution: invalid
Status: newclosed

Several notes:

  1. You can't use toupper or isalpha as they are locale sencitive and may accept characters outside of ASCII scope
  2. It does not the same, for example, the code allows to accept "-" and language-country separator

The code is so complex because it tries to do the best to guess the locale

It does allow invalid locale names

This is very important part, many OSes do very crazy stuff, so I try to guess as much as I can.

Sorry I can't accept this patch.

If you can improve the code readability and maintainablility without changing the scope if this function feel free to reopen this ticked and submit a new patch.

Thanks for your effort.

Note: See TracTickets for help on using tickets.