CodeSOD: And It's Collated |
As anyone whos ever written a c-style char * string knows, strings are much more complicated than they look. This is even more true in this modern era of Unicode and character encodings and multilingual applications. How does "a compare to a or 'a?
John Moores company sent some code to a contracting firm. They needed to strip off any diacritics and unusual characters when they were comparing strings, so that "a and a were treated as the same character when searching- a not uncommon problem. In Java, theres a special family of classes inheriting from Collator which can be used to solve exactly that problem. Now, most developers arent deeply familiar with these, so seeing a contractor that turns in a more home brewed approach is hardly surprising.
This approach goes above and beyond. It starts out bad, but not horrible: convert the string to their character codes, and then look at each one. What follows is a textbook example of why you dont write gigantic if-blocks using magic numbers as boundary conditions, including this gem:
if (index == 292 && index == 294) {
resultCharacterIndexes.add(68);//H
}
Yes, they only convert to a 68 (the letter H) when the index character is both 292 and 294, which may
| Комментировать | « Пред. запись — К дневнику — След. запись » | Страницы: [1] [Новые] |