1
0
mirror of https://github.com/gabemart/hipku.git synced 2024-10-05 18:30:54 +01:00

Better way to capitalize haiku

This commit is contained in:
lord63 2015-02-24 20:40:52 +08:00 committed by gabemart
parent 8768da7339
commit cf65e8bdfd
2 changed files with 8 additions and 46 deletions

27
dist/hipku.js vendored
View File

@ -264,7 +264,7 @@ function writeHaiku(wordArray, ipv6) {
/*
** Capitalize appropriate words
*/
schema = capitalizeHaiku(schema, nonWords);
schema = capitalizeHaiku(schema);
haiku = schema.join('');
return haiku;
@ -351,7 +351,7 @@ function getSchema(ipv6, octet) {
return [schema, nonWords];
}
function capitalizeHaiku(haikuArray, nonWords) {
function capitalizeHaiku(haikuArray) {
var period = '.';
/*
@ -361,32 +361,13 @@ function capitalizeHaiku(haikuArray, nonWords) {
for (var i = 1; i < haikuArray.length; i++) {
if (haikuArray[i] === period) {
var isWord;
if (haikuArray[i] === period && i + 2 < haikuArray.length) {
/*
** If the current entry is a period then the next entry will be
** a newLine or a space, so check two positions ahead and
** capitalize that entry, so long as it's a word
*/
isWord = true;
if (haikuArray[i + 2] === undefined ||
haikuArray[i + 2] === null ||
haikuArray[i + 2] === '') {
isWord = false;
}
for (var j = 0; j < nonWords.length; j++) {
if (haikuArray[i + 2] === nonWords[j]) {
isWord = false;
}
}
if (isWord) {
haikuArray[i + 2] = capitalizeWord(haikuArray[i + 2]);
}
haikuArray[i + 2] = capitalizeWord(haikuArray[i + 2]);
}
}

View File

@ -264,7 +264,7 @@ function writeHaiku(wordArray, ipv6) {
/*
** Capitalize appropriate words
*/
schema = capitalizeHaiku(schema, nonWords);
schema = capitalizeHaiku(schema);
haiku = schema.join('');
return haiku;
@ -351,7 +351,7 @@ function getSchema(ipv6, octet) {
return [schema, nonWords];
}
function capitalizeHaiku(haikuArray, nonWords) {
function capitalizeHaiku(haikuArray) {
var period = '.';
/*
@ -361,32 +361,13 @@ function capitalizeHaiku(haikuArray, nonWords) {
for (var i = 1; i < haikuArray.length; i++) {
if (haikuArray[i] === period) {
var isWord;
if (haikuArray[i] === period && i + 2 < haikuArray.length) {
/*
** If the current entry is a period then the next entry will be
** a newLine or a space, so check two positions ahead and
** capitalize that entry, so long as it's a word
*/
isWord = true;
if (haikuArray[i + 2] === undefined ||
haikuArray[i + 2] === null ||
haikuArray[i + 2] === '') {
isWord = false;
}
for (var j = 0; j < nonWords.length; j++) {
if (haikuArray[i + 2] === nonWords[j]) {
isWord = false;
}
}
if (isWord) {
haikuArray[i + 2] = capitalizeWord(haikuArray[i + 2]);
}
haikuArray[i + 2] = capitalizeWord(haikuArray[i + 2]);
}
}