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

always use the 'en-US' culture for .ToUpper() when creating the new property name #6404

Merged

Conversation

brettfo
Copy link
Member

@brettfo brettfo commented Oct 28, 2015

As per an internal discussion, it was decided that it was best to use the "en-US" culture when calling char.ToUpper() to create the new property's name. C# and VB share the same code path so only C# tests were added.

Fixes #5524.

// Make uppercase the first letter
return char.ToUpper(baseName[0]).ToString() + baseName.Substring(1);
// Make the first character upper case using the "en-US" culture
var firstCharacter = _englishUSCulture.TextInfo.ToUpper(baseName[0]);
Copy link
Member Author

Choose a reason for hiding this comment

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

The portable APIs don't have char.ToUpper(char, CultureInfo) but according to the reference source for that method, I can get the same result by using TextInfo.

Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment and point to the issue on github around why this was done?

@brettfo
Copy link
Member Author

brettfo commented Oct 28, 2015

Tagging @dotnet/roslyn-ide for review.

@brettfo brettfo added this to the 1.1 milestone Oct 28, 2015
@CyrusNajmabadi
Copy link
Member

Does this work properly if, say, I have accented characters? Or characters in a language like farsi/Arabic?

@tmat
Copy link
Member

tmat commented Oct 28, 2015

Why en-US and not invariant?

@brettfo
Copy link
Member Author

brettfo commented Oct 28, 2015

@CyrusNajmabadi: Good catch. I've added tests with Arabic, Spanish (leading accented character), and Greek identifiers.
@tmat: According to an email conversation I had with @davkean, the en-US culture is kept up to date while the invariant one is not (but I'm not 100% sure what the definition of 'kept up to date' means in this case.)

@davkean
Copy link
Member

davkean commented Oct 28, 2015

This code doesn't handle surrogates/logical characters split into multiple actual chars, but the code has always had this bug and we should treat this as a separate bug which I'll file.

@davkean
Copy link
Member

davkean commented Oct 28, 2015

@tmat I'll reverse the question, why invariant?

@tmat
Copy link
Member

tmat commented Oct 28, 2015

Because that's what one is supposed to use when not caring about a specific culture.

@davkean
Copy link
Member

davkean commented Oct 28, 2015

We do care about the culture here. If we had a way for the developer to say in VS "this is the culture/locale that I'm editing right now" then we would use that (it would never be invariant).

There aren't plans right now to add one, so this is a compromise. Based on that, we're choose the most likely language that a user is editing in, in this case, en-US.

For IntelliSense, we did a slightly different approach; we search using the current user's culture, and en-US, but here we have to choose one, so we went with en-US, as that was the least surprising.

@tmat
Copy link
Member

tmat commented Oct 28, 2015

I see. Sounds good then.

@@ -340,6 +341,7 @@ protected IMethodSymbol CreateGet(string originalFieldName, IFieldSymbol field,
}

private static readonly char[] s_underscoreCharArray = new[] { '_' };
private static CultureInfo _englishUSCulture = new CultureInfo("en-US");
Copy link
Contributor

Choose a reason for hiding this comment

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

We're allocating one of these for Completion, too. Worth sharing?

Copy link
Member Author

Choose a reason for hiding this comment

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

As soon as your PR with this gets merged I'll rebase and share.

Copy link
Contributor

Choose a reason for hiding this comment

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

My PR is merged. Thanks!

@Pilchie
Copy link
Member

Pilchie commented Oct 29, 2015

👍

1 similar comment
@rchande
Copy link
Contributor

rchande commented Oct 29, 2015

👍

… property name

includes tests with turkish, arabic, spanish, and greek identifiers
@brettfo brettfo force-pushed the encapsulate-field-english-culture branch from bd71abf to ead7af7 Compare October 29, 2015 20:47
@brettfo
Copy link
Member Author

brettfo commented Oct 29, 2015

Rebased to take @rchande's changes and share the CultureInfo object.

return char.ToUpper(baseName[0]).ToString() + baseName.Substring(1);
// Make the first character upper case using the "en-US" culture. See discussion at
// https://github.com/dotnet/roslyn/issues/5524.
var firstCharacter = CompletionRules.EnUSCultureInfo.TextInfo.ToUpper(baseName[0]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we extract that static out to some utility class somewhere? I'm sure @jasonmalinowski and couplingchecker would be weeping right now.

Copy link
Member Author

Choose a reason for hiding this comment

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

I considered adding Features\Core\Portable\Common\CultureSomethingHelper.cs but ultimately decided against it due to that class only containing one item, but I could be very easily convinced otherwise.

Copy link
Member

Choose a reason for hiding this comment

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

@davkean was suggesting that we have something like: CultureFallbacks, and also encapsulate the fallback comparison from @rchande's change there, so that all of that policy is in one place.

He also mentioned that we should use CultureInfo.GetCulture(), instead of new CultureInfo().

Copy link
Member Author

Choose a reason for hiding this comment

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

I spoke with @davkean offline and it was decided that to avoid churn in the stabilization branch this PR will be left as-is and I've filed issue #6442 to properly collect all usages of new CultureInfo("en-US").

Copy link
Member

Choose a reason for hiding this comment

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

@brettfo: thanks. I'll limit my weeping until that gets fixed.

@MattGertz
Copy link
Contributor

Approved pending successful tests (if related to Dustin's change, then OK).

@brettfo
Copy link
Member Author

brettfo commented Oct 29, 2015

test prtest/win/dbg/eta please

brettfo added a commit that referenced this pull request Oct 30, 2015
always use the 'en-US' culture for `.ToUpper()` when creating the new property name
@brettfo brettfo merged commit f96c8b9 into dotnet:stabilization Oct 30, 2015
@brettfo brettfo deleted the encapsulate-field-english-culture branch October 30, 2015 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants