Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils: Don't strip modifiers when stripping encoding #322

Merged
merged 2 commits into from
Jun 21, 2021

Conversation

iainlane
Copy link
Contributor

@iainlane iainlane commented Jun 7, 2021

We have some locales which are dupes if we do this, for example ca_ES.UTF-8 and ca_ES.UTF-8@valencia. The latter of these should become ca_ES@valencia in the output. That is what locale -a shows.

Previously as_locale_strip_encoding () modified the passed-in string in place. However, in the one place where don't g_strdup () the string before passing to this function, it is the key in a GHashTable. We can't do this, and only get away with it because the hash table isn't touched after this call. Fix the function to instead return a newly allocated string, and drop the g_strdup calls from the other call sites.

Add a small test for this function too.

ximion/appstream-generator#92

@iainlane
Copy link
Contributor Author

iainlane commented Jun 7, 2021

btw, bonus change to replace as_gstring_replace with upstream's new version, but I can drop that commit if you don't want it

src/as-utils.c Outdated Show resolved Hide resolved
src/as-utils.c Outdated Show resolved Hide resolved
src/as-utils.c Outdated Show resolved Hide resolved
@robert-ancell
Copy link
Contributor

Other than the minor changes above, LGTM, thanks @iainlane!

@iainlane iainlane force-pushed the strip-locale-keep-modifiers branch 3 times, most recently from 1567299 to 6816d54 Compare June 7, 2021 21:36
@iainlane
Copy link
Contributor Author

iainlane commented Jun 7, 2021

Merci for the review!

Copy link
Owner

@ximion ximion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good except for the mentioned changes. Since as_gstring_replace is no public API, can you, besides conditionally redirecting it to g_string_replace if that's available, also add the limit parameter and set that to 1 when using it to replace the UTF-8 "sometimes-suffix"? It'll probably not actually improve performance by an amount that matters, given how short the string is, but it's likely still nice to have.

src/as-utils.c Show resolved Hide resolved
src/as-yaml.c Outdated Show resolved Hide resolved
Iain Lane added 2 commits June 21, 2021 21:32
We have some locales which are dupes if we do this, for example
ca_ES.UTF-8 and ca_ES.UTF-8@valencia. The latter of these should become
ca_ES@valencia in the output. That is what `locale -a` shows.

Previously `as_locale_strip_encoding ()` modified the passed-in string
in place. However, in the one place where don't `g_strdup ()` the string
before passing to this function, it is the key in a `GHashTable`. We
can't do this, and only get away with it because the hash table isn't
touched after this call. Fix the function to instead return a newly
allocated string, and drop the `g_strdup` calls from the other call
sites.

Add a small test for this function too.

ximion/appstream-generator#92
Until we can depend on 2.68, it's probably best to standardise on one
implementation - also, this one is much simpler.
@iainlane iainlane force-pushed the strip-locale-keep-modifiers branch from 6816d54 to 8f8327b Compare June 21, 2021 20:35
@iainlane
Copy link
Contributor Author

All done. Please check the SPDX changes, as I don't know what those input strings are to know if it should be 1 or 0. (Might be easier for you to fix that up directly in this branch if you want - you should be able to force push to it and then merge.)

* Performs multiple search and replace operations on the given string.
*
* Returns: the number of replacements done, or 0 if @search is not found.
* g_string_replace:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a typo (c+p from glib)

src/as-utils.h Show resolved Hide resolved
@ximion ximion merged commit 7e48140 into ximion:master Jun 21, 2021
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.

3 participants