| 45 | |
| 46 | /* Count double-byte length characters */ |
| 47 | /* #32401 */ |
| 48 | /* Props: Ydoow for https://wordpress.org/plugins/word-count-with-double-byte-character/ whose code this is based on */ |
| 49 | function doubleCount( txt ){ |
| 50 | var counter = 0; |
| 51 | for( var i = 0; i < txt.length; i++ ){ |
| 52 | if( txt.charCodeAt( i ) > 255 ){ |
| 53 | counter++; |
| 54 | } |
| 55 | } |
| 56 | return counter; |
| 57 | } |
| 58 | |
| 59 | /* Count words */ |
| 60 | function wordCount( txt ){ |
| 61 | var counter = 0; |
| 62 | for( var i = 0; i< txt.length; i++ ){ |
| 63 | while( txt.charAt( i ) == ' ' || txt.charCodeAt( i ) > 255 || txt.charAt( i )=='\n' ){ |
| 64 | i++; |
| 65 | } |
| 66 | if( txt.charAt( i + 1 ) == ' '|| txt.charAt( i + 1 ) == '\n' || txt.charCodeAt( i + 1 ) > 255 || i == txt.length - 1 ){ |
| 67 | counter++; |
| 68 | } |
| 69 | } |
| 70 | return counter; |
| 71 | } |