@@ -73,17 +73,22 @@ |
||
73 | 73 | $characterDeficit = 0; //Gets incremented when an uppercase letter is encountered before $targetCharsPerWord characters have been collected since the last UC char. |
74 | 74 | $wordIndex = $targetWordLength; //HACK: keeps track of how many characters have been carried into the abbreviation since the last UC char |
75 | 75 | while ($stringIndex < strlen($strString)) { //Process the whole input string... |
76 | - if ($abbrevLength >= $targetLength) //...unless the abbreviation has hit the target length cap |
|
76 | + if ($abbrevLength >= $targetLength) { |
|
77 | + //...unless the abbreviation has hit the target length cap |
|
77 | 78 | break; |
79 | + } |
|
78 | 80 | $currentChar = $strString[$stringIndex++]; //Grab a character from the string, advance the string cursor |
79 | 81 | if (in_array($currentChar, $ucLetters)) { //If handling a UC char, consider it a new word |
80 | 82 | $characterDeficit += $targetWordLength - $wordIndex; //If UC chars are closer together than targetWordLength, keeps track of how many extra characters are required to fit the target length of the abbreviation |
81 | 83 | $wordIndex = 0; //Set the wordIndex to reflect a new word |
82 | 84 | } else if ($wordIndex >= $targetWordLength) { |
83 | - if ($characterDeficit == 0) //If the word is full and we're not short any characters, ignore the character |
|
85 | + if ($characterDeficit == 0) { |
|
86 | + //If the word is full and we're not short any characters, ignore the character |
|
84 | 87 | continue; |
85 | - else |
|
86 | - $characterDeficit--; //If we are short some characters, decrement the defecit and carry on with adding the character to the abbreviation |
|
88 | + } else { |
|
89 | + $characterDeficit--; |
|
90 | + } |
|
91 | + //If we are short some characters, decrement the defecit and carry on with adding the character to the abbreviation |
|
87 | 92 | } |
88 | 93 | $abbreviation .= $currentChar; //Add the character to the abbreviation |
89 | 94 | $abbrevLength++; //Increment abbreviation length |