mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-22 06:04:35 +00:00
Merge pull request #63 from josh-perry/title_case
string: add title_case
This commit is contained in:
commit
2762d4ada2
@ -6,6 +6,7 @@ package.path = package.path .. ";../?.lua"
|
||||
local assert = require("batteries.assert")
|
||||
local tablex = require("batteries.tablex")
|
||||
local identifier = require("batteries.identifier")
|
||||
local stringx = require("batteries.stringx")
|
||||
|
||||
-- tablex {{{
|
||||
|
||||
@ -196,3 +197,10 @@ local function test_ulid()
|
||||
assert(not ulid:match("[ILOU%l]"))
|
||||
end
|
||||
end
|
||||
|
||||
-- stringx
|
||||
local function test_title_case()
|
||||
local str = "the quick brown fox jumps over the lazy dog"
|
||||
|
||||
assert(stringx.title_case(str) == "The Quick Brown Fox Jumps Over The Lazy Dog")
|
||||
end
|
||||
|
@ -288,4 +288,13 @@ function stringx.split_and_trim(s, delim)
|
||||
return s
|
||||
end
|
||||
|
||||
--titlizes a string
|
||||
--"quick brown fox" becomes "Quick Brown Fox"
|
||||
function stringx.title_case(s)
|
||||
s = s:gsub("%s%l", string.upper)
|
||||
s = s:gsub("^%l", string.upper)
|
||||
|
||||
return s
|
||||
end
|
||||
|
||||
return stringx
|
||||
|
Loading…
Reference in New Issue
Block a user