Skip to content

Commit

Permalink
Add element.totitlecase
Browse files Browse the repository at this point in the history
Returns The Element In Title Case.
(Named as such to prevent conflicts with such tags as 'inventory.title')
Pretty straightforward tag
  • Loading branch information
mcmonkey4eva committed Dec 10, 2013
1 parent 456e9b3 commit 2764d48
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/Element.java
Expand Up @@ -688,6 +688,29 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
if (attribute.startsWith("lower"))
return new Element(element.toLowerCase()).getAttribute(attribute.fulfill(1));

// <--[tag]
// @attribute <e@element.totitlecase>
// @returns Element
// @description
// Returns The Value Of An Element In Title Case.
// -->
if (attribute.startsWith("totitlecase")) {
if (element.length() == 0) {
return new Element("").getAttribute(attribute.fulfill(1));
}
StringBuilder TitleCase = new StringBuilder(element.length());
String Upper = element.toUpperCase();
String Lower = element.toLowerCase();
TitleCase.append(Upper.charAt(0));
for (int i = 1; i < element.length(); i++) {
if (element.charAt(i - 1) == ' ')
TitleCase.append(Upper.charAt(i));
else
TitleCase.append(Lower.charAt(i));
}
return new Element(TitleCase.toString()).getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <el@element.substring[<#>(,<#>)]>
// @returns Element
Expand Down

0 comments on commit 2764d48

Please sign in to comment.