forked from qt-creator/qt-creator
Doc:A script to transform sentences to Qt title case
to-title-case.js contains the javascript function to convert to
Qt title case (up style).
to-title-case.html allows one to test the script interactively
in a browser.
Change-Id: I3fbd2477a26ae701775a8e5391a13f4f27f9f355
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@nokia.com>
This commit is contained in:
+32
File diff suppressed because one or more lines are too long
Executable
+34
@@ -0,0 +1,34 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>Qt Title Case</title>
|
||||
<script type="text/javascript" src="jquery.js"></script>
|
||||
<script type="text/javascript" src="to-title-case.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="../classic.css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
$('#tester').submit(function(){
|
||||
$('#titled').val($('#untitled').attr('value').toTitleCase());
|
||||
return false;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body><div id="container">
|
||||
<h1>Qt to Title Case</h1>
|
||||
<p>Converts the entered phrase to the title case format used by Qt: prepositions of less than 5 letters are lowercase unless at the end of a sentence.</p>
|
||||
<p>This script does not perform grammatical analysis, and therefore it might be wrong at times... Use your judgement, and if possible fix the script.</p>
|
||||
<form id="tester" action="">
|
||||
<p>
|
||||
<input id="untitled" type="text" value="Turn me into a title" />
|
||||
<input type="submit" value="Convert →" />
|
||||
<input id="titled" type="text">
|
||||
</p>
|
||||
</form>
|
||||
<hr/>
|
||||
<p>Derived from <a href="http://individed.com/code/to-title-case/">http://individed.com/code/to-title-case/</a> written by David Gouch after John Gruber's <a href="http://daringfireball.net/2008/08/title_case_update">post</a></p>
|
||||
</div></body>
|
||||
</html>
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Derived from To Title Case 1.1.2 <http://individed.com/code/to-title-case/>
|
||||
* Copyright (c) 2008-2011 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);
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user