Locale Sensitive Case Conversion Turkish
Case conversion changes meaning under the Turkish locale, so fixed words like protocol names must pin Locale.ROOT instead of trusting the default.
Code
import java.util.Locale;
public class CaseRules {
public static void main(String[] args) {
Locale turkish = Locale.of("tr", "TR");
// the default rule: i uppercases to I
System.out.println("root: " + "i".toUpperCase(Locale.ROOT));
// the Turkish rule: i becomes the dotted capital İ, a different character
System.out.println("tr: " + "i".toUpperCase(turkish));
// the split goes both ways: I lowercases to dotless ı, not i
System.out.println("tr lower: " + "I".toLowerCase(turkish));
// no-Locale overloads follow the JVM default locale; results can vary per machine
System.out.println("default: " + "i".toUpperCase());
// fixed words such as protocol names must pin Locale.ROOT for casing
System.out.println("header: " + "content-type".toUpperCase(Locale.ROOT));
}
}What the demo splits
Under Locale.ROOT, i uppercases to I, the rule every ASCII code path assumes. Passing Locale.of(“tr”, “TR”) instead makes the same call produce the dotted capital İ, a different code point with different matching semantics.
The split runs both directions: I under Turkish lowercases to dotless ı, not i. The no-Locale toUpperCase follows whatever the JVM default is, which is why the demo pins Locale.ROOT for content-type; fixed identifiers must not change shape per machine.
Points worth noting
- Turkish dotless ı and dotted İ are distinct Unicode letters.
- Default-locale calls are a portability hazard in protocol and wire code.
Interactive Tools for This Topic
JSON to Zod Schema ConverterInfer typed Zod z.object schemas from JSON payloads locally, supporting nested objects, merged array shapes, enums, nullable fields, and JSDoc comments.JSON Schema ValidatorValidate JSON data against a JSON Schema definition and get detailed error reports. Supports type checking, required fields, and common constraint validation.JSONL / NDJSON InspectorValidate NDJSON and JSON Lines line-by-line, pinpoint syntax errors by line number, analyze key frequencies and types, and export a pretty JSON array.A/B Test Sample Size CalculatorCalculate required per-variant sample size and experiment duration for two-proportion A/B tests from baseline conversion, MDE, alpha, and statistical power.
FAQ
- Why pin Locale.ROOT for protocol names?
- Without an explicit locale the JVM default decides; on a Turkish machine the dotted İ would corrupt fixed identifiers during uppercasing. Locale.ROOT keeps the ASCII rule everywhere.
Report a problem with this exampleOpens a pre-filled issue on GitHub.