- if(w("^7", theSize) == 0) // detect color codes support in the width function
- {
- // NOTE: when color codes are involved, this binary search is,
- // mathematically, BROKEN. However, it is obviously guaranteed to
- // terminate, as the range still halves each time - but nevertheless, it is
- // guaranteed that it finds ONE valid cutoff place (where "left" is in
- // range, and "right" is outside).
-
- // terencehill: the following code detects truncated ^xrgb tags (e.g. ^x or ^x4)
- // and decrease left on the basis of the chars detected of the truncated tag
- // Even if the ^xrgb tag is not complete/correct, left is decreased
- // (sometimes too much but with a correct result)
- // it fixes also ^[0-9]
- while(left >= 1 && substring(theText, left-1, 1) == "^")
- left-=1;
-
- if (left >= 2 && substring(theText, left-2, 2) == "^x") // ^x/
- left-=2;
- else if (left >= 3 && substring(theText, left-3, 2) == "^x")
- {
- ch = str2chr(theText, left-1);
- if( (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F') ) // ^xr/
- left-=3;
- }
- else if (left >= 4 && substring(theText, left-4, 2) == "^x")
- {
- ch = str2chr(theText, left-2);
- if ( (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F') )
- {
- ch = str2chr(theText, left-1);
- if ( (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F') ) // ^xrg/
- left-=4;
- }
- }
- }
-