Files
qt-creator/doc/titlecase/to-title-case.js
Nikolai Kosjar f1300df6b3 Strip BOM from files
Change-Id: I9167c016760fe1e8378cdf84144c4bed5cd4e57c
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-10-01 10:51:10 +00:00

24 lines
1.2 KiB
JavaScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Derived from To Title Case 1.1.2 <http://individed.com/code/to-title-case/>
* Copyright (c) 2008-2014 David Gouch, Fawzi Mohamed.
* Licensed under the MIT License.
*/
String.prototype.toTitleCase = function() {
return this.replace(/([\w&`'"“.@:\/\{\(\[<>_]+-? *)/g, function(match, p1, index, title) {
if (index > 0 && title.charAt(index - 2) !== ":" &&
match.search(/^(a(mid|nd?|s|t)?|b(ut|y)|down|e(re|n)|f(or|rom)|i(f|n(to)?)|lest|next|o(n(to)?|ver|f|r)|per|re|t(h(en?|an|ru)|o|ill)|u(p|nto)|v(ia|s?\.?)|with)[ \-]/i) > -1)
// expanded list of the lowercase words:
// a amid an and as at but by down ere en for from if in into lest
// next on onto over of or per re then than thru to till up unto via
// v vs v. vs.
return match.toLowerCase();
if (title.substring(index - 1, index + 1).search(/['"_{(\[]/) > -1)
return match.charAt(0) + match.charAt(1).toUpperCase() + match.substr(2);
if (match.substr(1).search(/[A-Z]+|&|[\w]+[._][\w]+/) > -1 ||
title.substring(index - 1, index + 1).search(/[\])}]/) > -1)
return match;
return match.charAt(0).toUpperCase() + match.substr(1);
});
};