Convert text between upper, title, camel and snake case
Converts text between upper, lower, title, sentence, camel, snake and kebab case, one line at a time. Title case follows the Chicago or the AP rules rather than putting a capital on every word, so "the lord of the rings" becomes "The Lord of the Rings" and not "The Lord Of The Rings".
Line by line
| 1 | the lord of the rings: the return of the king | The Lord of the Rings: The Return of the King |
| 2 | HTML parsing for the rest of us | HTML Parsing for the Rest of Us |
| 3 | state-of-the-art design | State-of-the-Art Design |
How it works
What this does
It rewrites a piece of text in a different case. Seven of them: upper, lower, title, sentence, camel, snake and kebab. Every line is treated as its own title, sentence or identifier, so a list of column headers converts in one pass and each heading keeps its own rules.
The part worth explaining is title case, because it is the one nearly every other converter gets wrong. Putting a capital on every word gives “The Lord Of The Rings”, and no published style guide agrees with that. Headline style lowercases articles, the coordinating conjunctions and prepositions, except when one of them opens or closes the title. That single rule is the difference between a title that looks typeset and one that looks automated.
The method
Title case is a list plus four positional rules. The list holds the words that stay lower case; everything absent from it is capitalised, including the verbs “is”, “be” and “are” that people most often expect to be lowered. These are the words Chicago lowers:
articles a an the
conjunctions and but for nor or
named by rule as to
prepositions about above across after against along amid among
around at atop before behind below beneath beside
besides between beyond by concerning despite down
during except from in inside into like near of off
on onto opposite out outside over past per regarding
round since than through throughout till toward
towards under underneath unlike until unto up upon
versus via with within without
AP uses the same words, but only the ones of three letters or fewer, because AP capitalises every word of four letters or more. That is the whole of the difference between the two settings: Chicago writes “A Walk through the Woods”, AP writes “A Walk Through the Woods”.
The four positional rules are that the first word of a line is capitalised, the last word is capitalised, the first word after a colon is capitalised, and a word directly following a hyphen is exempt from the first two. The last of those is what makes hyphenated compounds behave: “run-in with the law” becomes “Run-in with the Law” rather than “Run-In with the Law”, while “state-of-the-art” becomes “State-of-the-Art” because “art” is a noun and is not on the list at all.
Sentence case has one trap in it, and it is worth knowing about. Sentence boundaries come from the browser’s own implementation of the Unicode segmentation rules, which handle quotation marks, brackets, decimal numbers and abbreviations properly. But rule SB8 of that standard suppresses a sentence break when the next letter is lower case, on the reasonable ground that in ordinary prose a full stop followed by a small letter is an abbreviation. The input to a case converter is precisely the text that cannot be assumed to be cased correctly: segmenting “hello world. this is a test.” directly returns one sentence, so only the first capital ever appears. The segmenter is therefore run over a copy of the line with every letter raised, which leaves the offsets where they were and gives the standard nothing to suppress. On top of that, a sentence ending in a single initial or in one of twenty listed abbreviations is joined to the next, so “e.g. this” does not become “E.g. This”. The test file asserts that count, so it cannot drift.
Camel, snake and kebab case work on identifiers rather than words. Each word has its apostrophes removed, then is split wherever the case changes: a lower-case letter or a digit followed by a capital, and a run of capitals followed by a lower-case letter. The third of those is the one naive splitters miss, and it is why “parseHTMLDoc” comes out as parse, HTML, Doc rather than as five parts or one. Everything that is not a letter or a digit has already gone, so “Order # (net)” is order_net.
Nothing here is locale-sensitive. Upper and lower case use the Unicode default mappings, and the segmenters are built with a fixed locale, because the same text has to convert identically on every machine and a shared link must not convert differently for the person who opens it.
Before you read on
In Chicago title case, run-in with the law becomes Run-in with the Law. What does state-of-the-art design become?
State-of-the-Art Design. Those two examples look like they contradict each other and do not. A word directly following a hyphen is exempt from the first-word and last-word rules, which is why the in in Run-in stays lowered — but art is a plain noun that was never on the lower-case list, so nothing was ever going to keep it down. One rule decides whether a word is forced up; a different list decides whether it is held down.
first word of a line -> capitalWhatever it is. The Lord of the Rings starts with a capital T even though the is on the lower-case list.
last word of a line -> capitalSame reasoning at the other end, so a title never trails off in a preposition written small.
first word after a colon -> capitalA subtitle starts there. That is the The in The Return of the King.
word directly after a hyphen -> exempt from bothSo Run-in keeps its small i. Without this, every hyphenated compound at the start or end of a line would be capitalised twice over.
A worked example
The text the tool loads with is three lines chosen to exercise the rules:
the lord of the rings: the return of the king
HTML parsing for the rest of us
state-of-the-art design
Converted seven ways, with the Chicago rules and the acronym option on:
Title Case The Lord of the Rings: The Return of the King
HTML Parsing for the Rest of Us
State-of-the-Art Design
Sentence case The lord of the rings: the return of the king
HTML parsing for the rest of us
State-of-the-art design
UPPER CASE THE LORD OF THE RINGS: THE RETURN OF THE KING
HTML PARSING FOR THE REST OF US
STATE-OF-THE-ART DESIGN
lower case the lord of the rings: the return of the king
html parsing for the rest of us
state-of-the-art design
camelCase theLordOfTheRingsTheReturnOfTheKing
htmlParsingForTheRestOfUs
stateOfTheArtDesign
snake_case the_lord_of_the_rings_the_return_of_the_king
html_parsing_for_the_rest_of_us
state_of_the_art_design
kebab-case the-lord-of-the-rings-the-return-of-the-king
html-parsing-for-the-rest-of-us
state-of-the-art-design
Four things happened in the title case block. “of” and “the” were lowered because they are on the list. “The” after the colon was raised because a subtitle starts there. “HTML” survived because that line is not entirely in capitals, so the acronym option applied. And “State-of-the-Art” got a capital A because “art” is not on the list, while “of” and “the” beside it are.
The figures reported alongside are 3 lines, 22 words, 101 characters in and 101 characters out. In camelCase the output drops to 81 characters, because the spaces and the punctuation are gone.
These are the same numbers asserted in this tool’s test file, so if the rules ever change without this page changing with them, the build fails.
What it does not do
It does not understand grammar. Title case is a lookup against a list of function words, so a preposition doing an adverb’s job — “Look up the Answer” — is lowered where Chicago would capitalise it, and a word such as “so” or “like” is treated the same way wherever it appears. It does not restore proper nouns in sentence case, because the text no longer contains the information needed to; the pronoun I is the only word put back. It does not transliterate, so “café” stays “café” in snake_case rather than becoming “cafe”. It does not know what a name looks like, so “o’brien” is capitalised as “O’brien” rather than “O’Brien”. And upper case is not reversible: ß becomes SS and does not come back.
And it counts nothing. If you want to know how long the text is rather than change its case, a character count is the other half of the same job.
How it is done
- Fold Windows and classic Mac line endings to a single newline, then split the text into lines. Every line is converted on its own, so a list of headings or column names goes through in one pass.
- Decide whether the line is shouting, meaning it has capitals in it and no lower case at all. On such a line the option to leave words already in capitals alone is ignored, because nothing there marks one word out as an acronym.
- For upper and lower case, apply the Unicode default case mappings to the whole line and stop. Those mappings are locale-independent, so the German ß becomes SS and the answer is the same on every machine.
- For title case, find the words - runs of letters and digits, which may have apostrophes inside them. A hyphen is not part of a word, so each element of a hyphenated compound is judged separately.
- Capitalise the first word, the last word and the first word after a colon. Lowercase any other word on the chosen style's list. Capitalise everything else. A word that directly follows a hyphen is exempt from the first-and-last rule.
- For sentence case, lower every word, put the pronoun I back, then capitalise the first letter of each sentence. Sentence boundaries come from the browser's Unicode segmenter, run over a case-blind copy of the line.
- Join a sentence to the one before it when that one ends in a single initial or in one of twenty listed abbreviations, so a full stop after "e.g." or "Mr." does not produce a stray capital.
- For camel, snake and kebab case, take the same words, drop their apostrophes, and split each one on a change of case - a lower-case letter or a digit followed by a capital, and a run of capitals followed by a lower-case letter.
- Join the parts. Lower case throughout for snake and kebab; for camel, a lowered first part with every later part capitalised.
What it assumes
- Each line is converted on its own. A title's first and last word are the first and last word of its line, a sentence never runs across a line break, and twenty column headers on twenty lines become twenty identifiers rather than one long one.
- Title case is a word list, not a grammar. Chicago lowercases prepositions by looking them up, so a preposition used adverbially is lowered where Chicago would capitalise it - "Look up the Answer" rather than "Look Up the Answer". Getting that right needs a part-of-speech tagger, which is a far larger and far less predictable thing than a list.
- The first and last word of a line are always capitalised, along with the first word after a colon. A word directly following a hyphen is exempt from that rule, which is what produces "Run-in with the Law" rather than "Run-In with the Law".
- Leaving words already in capitals alone is ignored on a line that is entirely in capitals. An acronym is a word in capitals among words that are not, and a shouted line offers no such contrast, so honouring the option there would convert a caps-lock accident into itself.
- Sentence case cannot restore a proper noun. Nothing in "we met in paris" says that Paris is a city, so it comes back lower case. The pronoun I is the single exception, because it is unambiguous in a way a name is not.
- Title and sentence case lower the rest of every word, so a deliberately mixed-case word is flattened - "parseHTMLDoc" becomes "Parsehtmldoc". Camel, snake and kebab case are the conversions that understand an existing identifier.
- Acronyms are folded in camel, snake and kebab case whatever the option says. "Customer ID" becomes customer_id, because a snake_case name carrying capitals is neither snake_case nor easier to read.
- Upper and lower case use the Unicode default mappings with no locale attached. The German ß becomes SS, which is correct, and does not come back as ß, which means the change is not reversible. A Turkish dotless i is cased by the default rules rather than the Turkish ones.
- A word beginning with a digit is left as it is, so "1st" stays "1st" and "3d" stays "3d" rather than becoming "1St" and "3D".
- Characters are counted as grapheme clusters. An accented letter written as two code points, or an emoji with a skin-tone modifier written as four, counts as one.
Common questions
Is the text I am converting uploaded anywhere?
No. The conversion runs in this browser tab, on your machine, and there is no server to send it to. The page keeps the text in the link's fragment so that a result can be shared, and a fragment is the one part of a URL a browser never transmits.
Why is "of" lower case in the middle of my title?
Because that is what headline style says. Both Chicago and AP lowercase articles, the coordinating conjunctions and the short prepositions anywhere except the first and last word of the title. "The Lord Of The Rings" is the version almost every case converter produces and it is wrong in every published style guide. The full list of words this tool lowers is printed below.
Why did my acronym come back in lower case?
Almost certainly because the line it was on was entirely in capitals. On such a line there is nothing to tell USA apart from MEETING, so the option to leave capitals alone is ignored for that line - otherwise a message typed with caps lock on would convert into itself and the tool would look broken. Fix the acronym by hand, or lower the rest of the line first and convert again.
What is the difference between Chicago and AP title case?
The length of a preposition. Chicago lowercases every preposition however long it is, so it writes "A Walk through the Woods". AP capitalises any word of four letters or more, so it writes "A Walk Through the Woods". On short function words the two agree, which is why most titles come out identical either way.
Why is every line converted separately?
Because it is what makes a list work. Twenty column headers on twenty lines become twenty identifiers, and each heading in a list gets its own first-and-last-word rule instead of the whole block being treated as one very long title. It also means a blank line stays blank and keeps its place in the table below.
Why can sentence case not put my proper nouns back?
Because the information is gone. "we met in paris" contains nothing that says Paris is a city rather than a word, and a tool that guessed would be wrong often enough to be worse than one that does not. The pronoun I is restored, along with I'm, I've, I'll and I'd, because that one is unambiguous.
Why did STRASSE not turn back into Straße?
Because upper-casing ß produces SS and nothing records where it came from. The Unicode default mapping is one-way here, so "straße" upper-cased is STRASSE and STRASSE lower-cased is "strasse". The characters-in and characters-out figures differ by one when it happens, which is the signal that something irreversible has taken place.
Why is the box limited to 2,000 characters?
Because the whole state of the tool travels in the page link, and a link has to survive being pasted into a message. Two thousand characters is roughly one side of A4. For a whole document, convert it in sections, or use a tool that reads a file rather than a text box.