1
0
mirror of https://github.com/gabemart/hipku.git synced 2025-01-18 20:10:50 +00: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

25
dist/hipku.js vendored
View File

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

View File

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