Strings: case sensistive custom implementations

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m
Line 21: Line 21:
  
 
1) In the case of ignore-case comparisons we simply compare TO_CASE[ left_char ] to TO_CASE[ right_char ] with TO_CASE being either TO_UPPER ot TO_LOWER.
 
1) In the case of ignore-case comparisons we simply compare TO_CASE[ left_char ] to TO_CASE[ right_char ] with TO_CASE being either TO_UPPER ot TO_LOWER.
2) In the case of string case conversion, car become either TO_UPPER[ char ]  ot TO_LOWER[ char ].
+
<br>2) In the case of string case conversion, car become either TO_UPPER[ char ]  ot TO_LOWER[ char ].
  
image being uploaded, patience
+
 
 +
[[File:Case table conversion.jpg]]

Revision as of 04:13, 7 October 2020

Author: Serge Billault


The following tips are not meant to be absolutes but rather guidelines for Unity users that want to produce well performing code.

Scripting

Sometimes the need to implement custom case conversions for custom string classes arise. It is not for us to judge if the intiative is well founded but we can attract
the attention on some common pitfalls encounterd by those who attempt it for the first time.

In the 80s/90s, when we were cracking video games we would often notice in the BSS section of the executables some recuring data structures that were resembling
a 256 chraracters table hosting a variation of the alphabet. These are conversion tables. Conversion tables are used whenever a direct match exist between
a data to convert and the converted data using direct indexing. That's how we were so fast on systems running at 8 Mhz.

In the particular case of string case convertions, the same principle can be applied to printable letters using a conversion table. Such tables also exist for
conversion from integral values to hexadecimal literals.

Exemple

Table commonly used for case convertions and ignore-case comparisons.

1) In the case of ignore-case comparisons we simply compare TO_CASE[ left_char ] to TO_CASE[ right_char ] with TO_CASE being either TO_UPPER ot TO_LOWER.
2) In the case of string case conversion, car become either TO_UPPER[ char ] ot TO_LOWER[ char ].


Case table conversion.jpg

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox