Advertisement
ZoriaRPG

string_functions.zh Updated 17-July-2018

Jul 17th, 2018
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 31.94 KB | None | 0 0
  1. //string.zh
  2. //17-JULY-2018
  3. //ZScript string handling functions, akin to those found in C
  4.  
  5.  
  6. //memchr
  7. //Locate character in block of memory (function )
  8.  
  9. //strchr
  10. //Locate first occurrence of character in string (function )
  11. int strchr(int ptr, int chr)
  12. {
  13.     int q;
  14.     for ( ; ptr[q] != 'chr' ++q )
  15.     {
  16.         if ( ptr[q] == 0 ) return 0;
  17.     }
  18.     return q;
  19. }
  20.  
  21. //strcspn
  22. //Get span until character in string (function )
  23. int strcspn(int ptr, int chr)
  24. {
  25.     int rv; int q;
  26.     while ( ptr[q] != 'chr' )
  27.     {
  28.         if ( ptr[q] == 0 ) break;
  29.         ++rv;
  30.     }
  31.     return rv;
  32. }
  33.        
  34.  
  35. //strpbrk
  36. //Locate characters in string (function )
  37.  
  38. //strrchr
  39. //Locate last occurrence of character in string (function )
  40. int strrchr(int ptr, int chr)
  41. {
  42.     int q = SizeOfArray(ptr)-1;
  43.     for ( ; ptr[q] != 'chr' --q )
  44.     {
  45.         if ( q == 0 ) return 0;
  46.     }
  47.     return q;
  48. }
  49.  
  50. //strspn
  51. //Get span of character set in string (function )
  52. //strstr
  53. //Locate substring (function )
  54. //strtok
  55. //Split string into tokens (function )
  56.  
  57. //Returns the number of chracters of a given type in a specified string.
  58. int NumCharsOf(int str, int chr){
  59.     int chars; int sz = SizeOfArray(str)-1;
  60.     for ( int q = 0; q < sz; ++q ) {
  61.         if ( str[q] == chr ) ++chars;
  62.     }
  63.     return chars;
  64. }
  65.  
  66. int NumCharsOf(int str, int pos, int chr){
  67.     int chars; int sz = SizeOfArray(str)-1;
  68.     for ( int q = pos; q < sz; ++q ) {
  69.         if ( str[q] == chr ) ++chars;
  70.     }
  71.     return chars;
  72. }
  73.  
  74. //reversed
  75. //Returns the number of chracters of a given type in a specified string.
  76. int NumCharsOfRev(int str, int chr){
  77.     int chars; int sz = SizeOfArray(str)-1;
  78.     for ( int q = sz; q >= 0; --q ) {
  79.         if ( str[q] == chr ) ++chars;
  80.     }
  81.     return chars;
  82. }
  83.  
  84. int NumCharsOfRev(int str, int pos, int chr){
  85.     int chars;
  86.     for ( int q = pos; q >= 0; --q ) {
  87.         if ( str[q] == chr ) ++chars;
  88.     }
  89.     return chars;
  90. }
  91.  
  92. //Single character functions
  93. //Returns true if 'chr' is in the control code range of ascii characters
  94. bool isControlCode(int chr)
  95. {
  96.     if (chr >= 0)
  97.     {
  98.         if ( chr < ' ') return true;
  99.     }
  100.     return false;
  101. }
  102.  
  103. //Returns true if 'chr' is in the range of ascii characters '0' to '9'
  104. bool isNumber(int chr)
  105. {
  106.     if (chr >= '0')
  107.     {
  108.         if ( chr <= '9') return true;
  109.     }
  110.     return false;  
  111. }
  112.  
  113. //Returns true if 'chr' is an alphabetic character
  114. bool isAlphabetic(int chr)
  115. {
  116.     if (chr >= 'a')
  117.     {
  118.         if ( chr <= 'z') return true;
  119.     }
  120.    
  121.     if (chr >= 'A' )
  122.     {
  123.         if ( chr <= 'Z') return true;
  124.     }
  125.     return false;
  126. }
  127.  
  128. //Returns true if 'chr' is an alphanumeric character
  129. bool isAlphaNumeric(int chr)
  130. {
  131.     if (isNumber(chr)) return true;
  132.     if (isAlphabetic(chr)) return true;
  133.     return false;
  134. }
  135.  
  136. //Returns true if 'chr' is in the set { '0'-'9', 'A'-'F' , 'a'-'f' }
  137. bool isHex(int chr)
  138. {
  139.     if (isNumber(chr)) return true;
  140.     if (chr >= 'A' )
  141.     {
  142.         if(  chr <= 'F') return true;
  143.     }
  144.     if (chr >= 'a' )
  145.     {
  146.         if ( chr <= 'f') return true;
  147.     }
  148.     return false;
  149. }
  150.  
  151. //Returns true if 'chr' is an upper-case character
  152. bool isUpperCase(int chr)
  153. {
  154.     if (chr >= 'A')
  155.     {
  156.         if ( chr <= 'Z') return true;
  157.     }
  158.     return false;
  159. }
  160.  
  161. //Returns true if 'chr' is a lower-case character
  162. bool isLowerCase(int chr)
  163. {
  164.     if (chr >= 'a')
  165.     {
  166.         if ( chr <= 'z') return true;
  167.     }
  168.     return false;
  169. }
  170.  
  171. //Retruns true if a 'chr' is a blank space.
  172. bool isSpace(int chr){
  173.     return (chr == ' ');
  174. }
  175.  
  176. //Returns true if 'chr' is a vowel.
  177. bool isVowel(int chr)
  178. {   //this is not a randomly sequenced list. I sequenced it based on letter frequency in English. -Z
  179.     if (chr == 'e') return true;
  180.     if ( chr == 'a' ) return true;
  181.     if ( chr == 'A' ) return true;
  182.     if ( chr == 'E' ) return true;
  183.     if ( chr == 'I' ) return true;
  184.     if ( chr == 'o' ) return true;
  185.     if ( chr == 'O' ) return true;
  186.     if ( chr == 'i' ) return true;
  187.     if ( chr == 'u' ) return true;
  188.     if ( chr == 'U' ) return true;
  189.     return false;
  190. }
  191.  
  192. //Returns true if the string contains a specific character.
  193. bool ContainsChar(int chr, int buffer)
  194. {
  195.     int sz = SizeOfArray(buffer);
  196.     for ( int q = 0; q < sz; ++q )
  197.     {
  198.         if ( buffer[q] == chr ) return true;
  199.     }
  200.     return false;
  201. }
  202.  
  203. //Returns first character position if the string contains a specific character, else -1.
  204. int ContainsCharPos(int chr, int buffer){
  205.     int sz = SizeOfArray(buffer);
  206.     for ( int q = 0; q < sz; ++q )
  207.     {
  208.         if ( buffer[q] == chr ) return q;
  209.     }
  210.     return -1;
  211. }
  212.  
  213. //Returns true if the string contains a specific character.
  214. bool ContainsChar(int chr, int pos, int buffer)
  215. {
  216.     int sz = SizeOfArray(buffer);
  217.     for ( int q = pos; q < sz; ++q )
  218.     {
  219.         if ( buffer[q] == chr ) return true;
  220.     }
  221.     return false;
  222. }
  223.  
  224.  
  225.  
  226.  
  227.  
  228. //Returns first character position if the string contains a specific character, else -1.
  229. int ContainsCharPos(int chr, int pos, int buffer)
  230. {
  231.     int sz = SizeOfArray(buffer);
  232.     for ( int q = pos; q < sz; ++q )
  233.     {
  234.         if ( buffer[q] == chr ) return q;
  235.     }
  236.     return -1;
  237. }
  238.  
  239.  
  240. //Returns true if the string contains a specific character.
  241. bool ContainsCharRev(int chr, int buffer)
  242. {
  243.     for ( int q = (SizeOfArray(buffer)-1); q >= 0; --q )
  244.     {
  245.         if ( buffer[q] == chr ) return true;
  246.     }
  247.     return false;
  248. }
  249.  
  250. //Returns first character position if the string contains a specific character, else -1.
  251. int ContainsCharPosRev(int chr, int buffer)
  252. {
  253.     for ( int q = (SizeOfArray(buffer)-1); q >= 0; --q )
  254.     {
  255.         if ( buffer[q] == chr ) return q;
  256.     }
  257.     return -1;
  258. }
  259.  
  260.  
  261. //Returns true if the string contains a specific character.
  262. bool ContainsCharRev(int chr, int pos, int buffer)
  263. {
  264.     for ( int q = pos; q >= 0; --q )
  265.     {
  266.         if ( buffer[q] == chr ) return true;
  267.     }
  268.     return false;
  269. }
  270.  
  271. //Returns first character position if the string contains a specific character, else -1.
  272. int ContainsCharPosRev(int chr, int pos, int buffer)
  273. {
  274.     for ( int q = pos; q >= 0; --q )
  275.     {
  276.         if ( buffer[q] == chr ) return q;
  277.     }
  278.     return -1;
  279. }
  280.  
  281.  
  282. //Converts all upper case characters to lower case, leaving non-alphabetic
  283. //characters unchanged
  284. int UpperToLower(int chr)
  285. {
  286.     if(!isAlphabetic(chr))
  287.         return chr;
  288.     return Cond(isLowerCase(chr), chr, chr + ('a' - 'A'));
  289. }
  290.  
  291. //Converts all lower case characters to upper case, leaving non-alphabetic
  292. //characters unchanged
  293. int LowerToUpper(int chr)
  294. {
  295.     if(!isAlphabetic(chr))
  296.         return chr;
  297.     return Cond(isLowerCase(chr), chr - ('a' - 'A'), chr);
  298. }
  299.  
  300. //Converts lower case to upper case and upper case to lower case
  301. int ConvertCase(int chr)
  302. {
  303.     if(!isAlphabetic(chr))
  304.         return chr;
  305.     return chr + Cond(isLowerCase(chr), 'A' - 'a', 'a' - 'A');
  306. }
  307.  
  308.  
  309. //Memory Manipulation
  310. //Memory Set
  311. //Sets block of memory of size 'n' pointed by 'ptr' to 'value'
  312. void memset(int ptr, int pos, int value, int n)
  313. {
  314.     for(int i = 0; i < n; ++i)
  315.         ptr[pos + i] = value;
  316. }
  317. void memset(int ptr, int value, int n)
  318. {
  319.     memset(ptr, 0, value, n);
  320. }
  321.  
  322. //Memory Copy
  323. //Copys block of memory pointed by 'src' of size 'n' to 'dest'
  324. void memcpy(int dest, int dpos, int src, int spos, int n)
  325. {
  326.     for(int i = 0; i < n; ++i)
  327.         dest[dpos + i] = src[spos + i];
  328. }
  329. void memcpy(int dest, int src, int n)
  330. {
  331.     memcpy(dest, 0, src, 0, n);
  332. }
  333.  
  334. //Memory Move
  335. //As memcpy, but uses a buffer so memory space can overlap
  336. int memmove(int dest, int dpos, int src, int spos, int n)
  337. {
  338.     int buffer[0x100];
  339.     for(int i = 0; i < n; ++i)
  340.         buffer[i] = src[spos + i];
  341.     for(int i = 0; i < n; ++i)
  342.         dest[dpos + i] = buffer[i];
  343.     return dest;
  344. }
  345.  
  346.  
  347. //Array Set
  348. //Assign all elements of array. Overloaded.
  349. void arrayset(int a,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,
  350.                     int a8,int a9,int aa,int ab,int ac,int ad,int ae,int af){
  351.     a[0x0] = a0; a[0x1] = a1; a[0x2] = a2; a[0x3] = a3; a[0x4] = a4; a[0x5] = a5; a[0x6] = a6; a[0x7] = a7;
  352.     a[0x8] = a8; a[0x9] = a9; a[0xa] = aa; a[0xb] = ab; a[0xc] = ac; a[0xd] = ad; a[0xe] = ae; a[0xf] = af;
  353. }
  354.  
  355.  
  356. //String Manipulation
  357. //String Copy
  358. //Copys string 'src' into string 'dest' without checking for overflow in 'dest'
  359. void strcpy(int dest, int dpos, int src, int spos)
  360. {
  361.     for(int i = 0; src[spos + i] != 0; ++i)
  362.         dest[dpos + i] = src[spos + i];
  363. }
  364. void strcpy(int dest, int src)
  365. {
  366.     strcpy(dest, 0, src, 0);
  367. }
  368.  
  369. //As strcpy, but only takes the first 'n' characters from src
  370. void strncpy(int dest, int dpos, int src, int spos, int n)
  371. {
  372.     for(int i = 0; src[spos + i] != 0 && i < n; ++i)
  373.         dest[dpos + i] = src[spos + i];
  374. }
  375. void strncpy(int dest, int src, int n)
  376. {
  377.     strncpy(dest, 0, src, 0, n);
  378. }
  379.  
  380. //Remove Characters
  381. //Remove all characters starting from pointer 'string'
  382. void remchr(int string, int pos)
  383. {
  384.     for(int i = 0; string[pos + i] != 0; ++i)
  385.         string[pos + i] = 0;
  386. }
  387.  
  388. //Remove 'n' characters and shift string back to pointer 'string'
  389. void remnchr(int string, int pos, int n)
  390. {
  391.     int l = strlen(string);
  392.     int temp = n + pos;
  393.     for(int i = 0; string[pos + i] != 0; ++i)
  394.         string[pos + i] = Cond(temp + i < l, string[temp + i] ,0);
  395. }
  396.  
  397. //String Length
  398. //Returns the length of string 'string'
  399. int strlen(int string)
  400. {
  401.     int l;
  402.     for(l = 0; string[l] != 0; ++l);
  403.     return l;
  404. }
  405.  
  406. //String Concatenate
  407. //Appends string 'src' onto string 'dest' (assuming dest has enough extra memory
  408. //allocated to allow the operation)
  409. void strcat(int dest, int src, int spos)
  410. {
  411.     int i;
  412.     int l = strlen(dest);
  413.     for(i = 0; src[spos + i] != 0; ++i)
  414.         dest[l + i] = src[spos + i];
  415.     dest[l + i] = 0;
  416. }
  417. void strcat(int dest, int src)
  418. {
  419.     strcat(dest, src, 0);
  420. }
  421.  
  422. //strcat up to 'n' characters in src
  423. void strncat(int dest, int src, int spos, int n)
  424. {
  425.     int i;
  426.     int l = strlen(dest);
  427.     for(i = 0; src[spos + i] != 0 && i < n; ++i)
  428.         dest[l + i] = src[spos + i];
  429.     dest[l + i] = 0;
  430. }
  431. void strncat(int dest, int src, int n)
  432. {
  433.     strncat(dest, src, 0, n);
  434. }
  435.  
  436.  
  437. //String Searching
  438. //String Character
  439. //Returns the position of the first occurence of 'character' in 'string',
  440. //or -1 if none are found
  441. int strchr(int string, int pos, int chr)
  442. {
  443.     for(int i = 0; string[pos + i] != 0; ++i)
  444.         if(string[pos + i] == chr)
  445.             return pos + i;
  446.     return -1;
  447. }
  448. int strchr(int string, int chr)
  449. {
  450.     return strchr(string, 0, chr);
  451. }
  452.  
  453. //String Reverse Character
  454. //Returns the position of the last occurence of 'character' in 'string'
  455. //starting from the end, or -1 if none are found
  456. int strrchr(int string, int pos, int chr)
  457. {
  458.     for(int i = strlen(string) - pos; i > 0; --i)
  459.         if(string[i] == chr)
  460.             return i;
  461.     return -1;
  462. }
  463. int strrchr(int string, int chr)
  464. {
  465.     return strrchr(string, 0, chr);
  466. }
  467.  
  468.  
  469. //String Sub-String
  470. //Returns the position of the first occurence of sub-string 'sub' in 'string',
  471. //or -1 if sub is not found
  472. int strstr(int string, int pos, int sub)
  473. {
  474.     int l = strlen(sub) - 1;
  475.     for(int i = 0; string[pos + i] != 0; ++i)
  476.         for(int j = 0; sub[j] != 0 && string[pos + i + j] != 0 && string[pos + i + j] == sub[j]; ++j)
  477.             if(j == l)
  478.                 return pos + i;
  479.     return -1;
  480. }
  481. int strstr(int string, int sub)
  482. {
  483.     return strstr(string, 0, sub);
  484. }
  485.  
  486. //String Span
  487. //Returns the length of characters in 'str' before a character not contained in
  488. //'keys' is found
  489. int strspn(int str, int pos, int keys)
  490. {
  491.     int i;
  492.     bool found;
  493.     for(i = 0; str[pos + i] != 0; ++i)
  494.     {
  495.         found = false;
  496.         for(int j = 0; keys[j] != 0; ++j)
  497.             if(str[pos + i] == keys[j])
  498.                 found = true;
  499.         if(!found)
  500.             return pos + i;
  501.     }
  502.     return pos + i;
  503. }
  504. int strspn(int str, int keys)
  505. {
  506.     return strspn(str, 0, keys);
  507. }
  508.  
  509. //String Complement Span
  510. //Returns the length of characters in 'str' before a character contained in
  511. //'keys' is found
  512. int strcspn(int str, int pos, int keys)
  513. {
  514.     int i;
  515.     for(i = 0; str[pos + i] != 0; ++i)
  516.         for(int j = 0; keys[j] != 0; ++j)
  517.             if(str[pos + i] == keys[j])
  518.                 return pos + i;
  519.     return pos + i;
  520. }
  521. int strcspn(int str, int keys)
  522. {
  523.     return strcspn(str, 0, keys);
  524. }
  525.  
  526. //String Comparison
  527. //String Compare
  528. //Iterates through str1 and str2 until a character is found which is not the same in
  529. //both strings, and then returns > 0 if the character is larger in str1, and < 0 if it is
  530. //larger in str2. Returns 0 if the strings are equal
  531. int strcmp(int str1, int pos1, int str2, int pos2)
  532. {
  533.     int i;
  534.     for(i = 0; str1[pos1 + i] != 0 && str2[pos2 + i] != 0 && str1[pos1 + i] == str2[pos2 + i]; ++i);
  535.     return str1[pos1 + i] - str2[pos2 + i];
  536. }
  537. int strcmp(int str1, int str2)
  538. {
  539.     return strcmp(str1, 0, str2, 0);
  540. }
  541.  
  542. //strcmp up to 'n' characters
  543. int strncmp(int str1, int pos1, int str2, int pos2, int n)
  544. {
  545.     int i;
  546.     for(i = 0; str1[pos1 + i] != 0 && str2[pos2 + i] != 0 && str1[pos1 + i] == str2[pos2 + i] && i < n; ++i);
  547.     if(i == n)
  548.         i--;
  549.     return str1[pos1 + i] - str2[pos2 + i];
  550. }
  551. int strncmp(int str1, int str2, int n)
  552. {
  553.     return strncmp(str1, 0, str2, 0 , n);
  554. }
  555.  
  556.  
  557. //Converting between variables and strings
  558. //ASCII to Integer
  559. //Returns the decimal integer pointed by 'string'
  560. int atoi(int string, int pos)
  561. {
  562.     int i=0;
  563.     bool neg = false;
  564.     if(string[pos + i] == '-'){
  565.         ++i;
  566.         neg = true;
  567.     }
  568.     int ret;
  569.     for(ret = 0; isNumber(string[pos + i]); ++i)
  570.         ret = ret*10 + (string[pos + i] - '0');
  571.     return ret*Cond(neg, -1, 1);
  572. }
  573. int atoi(int string)
  574. {
  575.     return atoi(string, 0);
  576. }
  577.  
  578. //Integer Length
  579. //Returns the length of characters of the decimal integer pointed by 'string'
  580. int ilen(int string, int pos)
  581. {
  582.     int ret = 0;
  583.     if(string[pos] == '-')
  584.         ret++;
  585.     for(; isNumber(string[pos + ret]); ++ret);
  586.     return ret;
  587. }
  588. int ilen(int string)
  589. {
  590.     return ilen(string, 0);
  591. }
  592.  
  593. //Hexadecimal ASCII to Integer
  594. //Returns the (positive) hexadecimal integer pointed by 'string'
  595. int xtoi(int string, int pos)
  596. {
  597.     int ret = 0;
  598.     for(int i = 0; isHex(string[pos + i]); ++i)
  599.         ret = ret*0x10 + Cond(isNumber(string[pos + i]), string[pos + i] - '0', LowerToUpper(string[pos + i]) - ('A' + 0xA));
  600.     return ret;
  601. }
  602. int xtoi(int string)
  603. {
  604.     return xtoi(string, 0);
  605. }
  606.  
  607. //Hexadecimal Length
  608. //Returns the length of characters of the (positive) hexadecimal integer pointed by 'string'
  609. int xlen(int string, int pos)
  610. {
  611.     int ret = 0;
  612.     for(; isHex(string[pos + ret]); ++ret);
  613.     return ret;
  614. }
  615. int xlen(int string)
  616. {
  617.     return xlen(string, 0);
  618. }
  619.  
  620. //ASCII to Float
  621. //Returns the floating point number pointed by 'string'
  622. float atof(int string, int pos)
  623. {
  624.     int i = 0;
  625.     bool neg = false;
  626.     if(string[pos + i] == '-')
  627.     {
  628.         ++i;
  629.         neg = true;
  630.     }
  631.  
  632.     int ret = 0;
  633.     for(; isNumber(string[pos + i]); ++i)
  634.         ret = ret*10 + (string[pos + i]-'0');
  635.  
  636.     if(string[pos + i] != '.')
  637.         return ret;
  638.     i++;
  639.  
  640.     int decimal = 0;
  641.     for(int j = 0; j < 4; ++j)
  642.         decimal = decimal*10 + Cond(isNumber(string[pos + i + j]), (string[pos + i + j] - '0'), 0);
  643.  
  644.     return (ret + decimal / 10000) * Cond(neg, -1, 1);
  645. }
  646. float atof(int string)
  647. {
  648.     return atof(string, 0);
  649. }
  650.  
  651. //Float Length
  652. //Returns the length of characters of the floating point number pointed by 'string'
  653. int flen(int string, int pos)
  654. {
  655.     int ret = ilen(string, pos);
  656.  
  657.     if(string[pos + ret] != '.')
  658.         return ret;
  659.     ++ret;
  660.  
  661.     return ret + ilen(string, pos + ret);
  662. }
  663. int flen(int string)
  664. {
  665.     return flen(string, 0);
  666. }
  667.  
  668. //ASCII to Number
  669. //Calls either atoi or atof depending on context
  670. int aton(int string, int pos)
  671. {
  672.     int i = 0;
  673.     if(string[pos + i] == '-')
  674.         i++;
  675.     for(; isNumber(string[pos + i]); ++i);
  676.  
  677.     if(string[pos + i] == '.')
  678.         return atof(string, pos);
  679.     else
  680.         return atoi(string, pos);
  681. }
  682. int aton(int string)
  683. {
  684.     return aton(string, 0);
  685. }
  686.  
  687. //Number Length
  688. //Calls either flen or ilen depending on context
  689. int nlen(int string, int pos)
  690. {
  691.     int i = 0;
  692.     if(string[pos + i] == '-')
  693.         i++;
  694.     for(; isNumber(string[pos + i]); ++i);
  695.  
  696.     if(string[i] == '.')
  697.         return flen(string, pos);
  698.     else
  699.         return ilen(string, pos);
  700. }
  701. int nlen(int string)
  702. {
  703.     return nlen(string, 0);
  704. }
  705.  
  706. //Integer to ASCII
  707. //Places integer 'num' into string 'string' without checking for overflow,
  708. //and returns the number of characters used
  709. int itoa(int string, int pos, int num)
  710. {
  711.     int ret = 0;
  712.     if(num < 0)
  713.     {
  714.         string[pos] = '-';
  715.         ++ret;
  716.         num = -num;
  717.     }
  718.     else if(num == 0)
  719.     {
  720.         string[pos] = '0';
  721.         return 1;
  722.     }
  723.  
  724.     int digits = Floor(Log10(num) + 1);
  725.     for(int i = 0; i < digits; ++i)
  726.         string[pos + ret + i] = (Floor(num / Pow(10, digits - i - 1)) % 10) + '0';
  727.     return ret + digits;
  728. }
  729. int itoa(int string, int num)
  730. {
  731.     return itoa(string, 0, num);
  732. }
  733.  
  734. //Hexadecimal Integer to ASCII
  735. //Places integer 'num' into string 'string' in base 16 without checking for overflow,
  736. //and returns the number of characters used
  737. int xtoa(int string, int pos, int num, bool upper)
  738. {
  739.     num = Floor(Abs(num));
  740.     string[pos] = '0';
  741.     string[pos+1] = 'x';
  742.     int ret = 2;
  743.  
  744.     if(num == 0)
  745.     {
  746.         string[pos+2] = '0';
  747.         return 3;
  748.     }
  749.  
  750.     int digits = Floor(LogToBase(num, 16) + 1);
  751.     int alphaoffset = Cond(upper, 'A' - 0xA, 'a' - 0xa);
  752.     for(int i = 0; i < digits; ++i)
  753.     {
  754.         int coeff = (Floor(num / Pow(0x10, digits - i - 1)) % 0x10);
  755.         string[pos + ret + i] = Cond(coeff < 0xA, coeff + '0', coeff + alphaoffset);
  756.     }
  757.     return ret + digits;
  758. }
  759. int xtoa(int string, int num, bool upper)
  760. {
  761.     return xtoa(string, 0, num, upper);
  762. }
  763. int xtoa(int string, int num)
  764. {
  765.     return xtoa(string, 0, num, true);
  766. }
  767.  
  768. //Float to ASCII
  769. //Places float 'num' into string 'string' without checking for overflow,
  770. //and returns the number of characters used. If 'printall' is true, it will add 4 decimal places
  771. //regardless of the most significant digit
  772. int ftoa(int string, int pos, float num, bool printall)
  773. {
  774.     int oldPos=pos;
  775.     int place=100000;
  776.     int digit;
  777.     bool printZero=false;
  778.     int storedZeroes=0;
  779.    
  780.     if(num<0)
  781.     {
  782.         string[pos]='-';
  783.         ++pos;
  784.         num=-num;
  785.     }
  786.        
  787.    
  788.     for(int i=0; i<10; ++i)
  789.     {
  790.         digit=((num/place)<<0)%10;
  791.        
  792.         // If the fractional part hasn't been reached yet, or
  793.         // if all four of its digits are to be printed, this is easy.
  794.         if(place>=1 || printall)
  795.         {
  796.             if(digit>0 || printZero)
  797.             {
  798.                 string[pos]=digit+'0';
  799.                 ++pos;
  800.                
  801.                 // Start printing 0 at the first non-zero digit.
  802.                 printZero=true;
  803.             }
  804.         }
  805.        
  806.         // Otherwise, it's trickier.
  807.         else
  808.         {
  809.             // A zero isn't printed unless there's something else after it.
  810.             // Don't print it, just keep count.
  811.             if(digit==0)
  812.                 ++storedZeroes;
  813.            
  814.             // Any other digit flushes the zeroes and then is printed.
  815.             else
  816.             {
  817.                 for(; storedZeroes>0; storedZeroes--)
  818.                 {
  819.                     string[pos]='0';
  820.                     ++pos;
  821.                 }
  822.                
  823.                 string[pos]=digit+'0';
  824.                 ++pos;
  825.             }
  826.         }
  827.        
  828.         num%=place; // To make sure num/place doesn't overflow when place<1
  829.         place/=10;
  830.        
  831.         if(place==1) // Last digit before the decimal point
  832.             printZero=true;
  833.        
  834.         else if(place==0.1) // Reached the fractional part
  835.         {
  836.             string[pos]='.';
  837.             ++pos;
  838.         }
  839.     }
  840.    
  841.     if(storedZeroes==4)
  842.     {
  843.         // printall is false and the number is an integer;
  844.         // just add one zero to the end.
  845.         string[pos]='0';
  846.         ++pos;
  847.     }
  848.    
  849.     return pos-oldPos;
  850. }
  851. int ftoa(int string, float num, bool printall)
  852. {
  853.     return ftoa(string, 0, num, printall);
  854. }
  855. int ftoa(int string, int pos, float num)
  856. {
  857.     return ftoa(string, pos, num, false);
  858. }
  859. int ftoa(int string, float num)
  860. {
  861.     return ftoa(string, 0, num, false);
  862. }
  863.  
  864. //Number to ASCII
  865. //Checks whether 'num' is an integer or not, and calls the appropriate function
  866. int ntoa(int string, int pos, float num)
  867. {
  868.     if(num == Floor(num))
  869.         return itoa(string, pos, num);
  870.     else
  871.         return ftoa(string, pos, num, false);
  872. }
  873. int ntoa(int string, float num)
  874. {
  875.     return ntoa(string, 0, num);
  876. }
  877.  
  878.  
  879. //String Formating
  880. //String Concatenate Format
  881. //Appends 'arg' onto 'dest' as the MF_ constant passed into 'format'
  882. void strcatf(int dest, int arg, int format)
  883. {
  884.     if(format == MF_INT)
  885.     {
  886.         int buffer[0x20];
  887.         itoa(buffer, arg);
  888.         strcat(dest, buffer);
  889.     }
  890.     else if(format == MF_HEXLOWER)
  891.     {
  892.         int buffer[0x20];
  893.         xtoa(buffer, arg, false);
  894.         strcat(dest, buffer);
  895.     }
  896.     else if(format == MF_HEXUPPER)
  897.     {
  898.         int buffer[0x20];
  899.         xtoa(buffer, arg, true);
  900.         strcat(dest, buffer);
  901.     }
  902.     else if(format == MF_FLOAT)
  903.     {
  904.         int buffer[0x20];
  905.         ftoa(buffer, arg, false);
  906.         strcat(dest, buffer);
  907.     }
  908.     else if(format == MF_FLOAT)
  909.     {
  910.         int buffer[0x20];
  911.         ftoa(buffer, arg, false);
  912.         strcat(dest, buffer);
  913.     }
  914.     else if(format == MF_NUM)
  915.     {
  916.         int buffer[0x20];
  917.         ntoa(buffer, arg);
  918.         strcat(dest, buffer);
  919.     }
  920.     else if(format == MF_PTR)
  921.     {
  922.         int buffer[0x20];
  923.         itoa(buffer, arg);
  924.         strcat(dest, buffer);
  925.     }
  926.     else if(format == MF_CHAR)
  927.     {
  928.         int buffer[0x2];
  929.         arrayset(buffer, arg, 0);
  930.         strcat(dest, buffer);
  931.     }
  932.     else if(format == MF_STRING && arg != 0)
  933.         strcat(dest, arg);
  934.  
  935. }
  936.  
  937. //As strcatf, using only 'n' characters of 'arg'
  938. void strncatf(int dest, int arg, int format, int n)
  939. {
  940.     if(format == MF_INT)
  941.     {
  942.         int buffer[0x20];
  943.         itoa(buffer, arg);
  944.         strncat(dest, buffer, n);
  945.     }
  946.     else if(format == MF_HEXLOWER)
  947.     {
  948.         int buffer[0x20];
  949.         xtoa(buffer, arg, false);
  950.         strncat(dest, buffer, n);
  951.     }
  952.     else if(format == MF_HEXUPPER)
  953.     {
  954.         int buffer[0x20];
  955.         xtoa(buffer, arg, true);
  956.         strncat(dest, buffer, n);
  957.     }
  958.     else if(format == MF_FLOAT)
  959.     {
  960.         int buffer[0x20];
  961.         ftoa(buffer, arg, false);
  962.         strncat(dest, buffer, n);
  963.     }
  964.     else if(format == MF_NUM)
  965.     {
  966.         int buffer[0x20];
  967.         ntoa(buffer, arg);
  968.         strncat(dest, buffer, n);
  969.     }
  970.     else if(format == MF_PTR)
  971.     {
  972.         int buffer[0x20];
  973.         itoa(buffer, arg);
  974.         strncat(dest, buffer, n);
  975.     }
  976.     else if(format == MF_CHAR)
  977.     {
  978.         int buffer[0x2];
  979.         arrayset(buffer, arg, 0);
  980.         strncat(dest, buffer, n);
  981.     }
  982.     else if(format == MF_STRING && arg != 0)
  983.         strncat(dest, arg, n);
  984.  
  985. }
  986.  
  987. //String Print Format
  988. //Prints string 'formatstr' into 'ret' according to the arguments inputted (see C function for reference)
  989. //Maximum 16 arguments
  990. int sprintf(int ret,int formatstr,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,
  991.                                   int a8,int a9,int aa,int ab,int ac,int ad,int ae,int af)
  992. {
  993.     int pos = 0;
  994.     int currentarg = 0;
  995.     int a[0x10];
  996.     arrayset(a,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,aa,ab,ac,ad,ae,af);
  997.  
  998.     for(int i = 0; formatstr[i] != 0; ++i)
  999.     {
  1000.         int chr = formatstr[i];
  1001.         if(chr == '\') //Control code
  1002.         {
  1003.             int nextchr = formatstr[i + 1];
  1004.             if(nextchr == 'n')
  1005.             {
  1006.                 ret[pos] = MSGC_LINEFEED;
  1007.                 ++pos;
  1008.                 ++i;
  1009.                 continue;
  1010.             }
  1011.         }
  1012.         else if(chr == '%') //Format argument
  1013.         {
  1014.             int nextchr = formatstr[i + 1];
  1015.             if(sprintf_isMFCode(nextchr))
  1016.             {
  1017.                 strcatf(ret, a[currentarg], sprintf_MFCodeToInt(nextchr));
  1018.                 for(; ret[pos] != 0; ++pos);
  1019.                 ++currentarg;
  1020.                 ++i;
  1021.                 continue;
  1022.             }
  1023.         }
  1024.  
  1025.         ret[pos] = chr;
  1026.         ++pos;
  1027.     }
  1028.  
  1029.     return pos;
  1030. }
  1031.  
  1032. //Print Format
  1033. //Uses a buffer to print the results of sprintf(formatstr,...) straight to allegro.log
  1034. void printf(int formatstr,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,
  1035.                           int a8,int a9,int aa,int ab,int ac,int ad,int ae,int af)
  1036. {
  1037.     int buffer[0x200]; //Max TraceS length is 512
  1038.     sprintf(buffer,formatstr,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,aa,ab,ac,ad,ae,af);
  1039.     TraceS(buffer);
  1040. }
  1041.  
  1042. //Used by sprintf
  1043. bool sprintf_isMFCode(int chr)
  1044. {
  1045.     return (chr == 'n' || chr == 's' || chr == 'i' || chr == 'f' || chr == 'd' ||
  1046.            chr == 'p' || chr == 'c' || chr == 'x' || chr == 'X');
  1047. }
  1048. int sprintf_MFCodeToInt(int chr)
  1049. {
  1050.     if(chr == 'n') return MF_NONE;
  1051.     else if(chr == 'i') return MF_INT;
  1052.     else if(chr == 'f') return MF_FLOAT;
  1053.     else if(chr == 'd') return MF_NUM;
  1054.     else if(chr == 's') return MF_STRING;
  1055.     else if(chr == 'p') return MF_PTR;
  1056.     else if(chr == 'c') return MF_CHAR;
  1057.     else if(chr == 'x') return MF_HEXLOWER;
  1058.     else if(chr == 'X') return MF_HEXUPPER;
  1059.     return -1;
  1060. }
  1061.  
  1062.  
  1063. //Function overloads
  1064. int sprintf(int ret,int formatstr,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,
  1065.                                    int a8,int a9,int aa,int ab,int ac,int ad,int ae){
  1066.     return sprintf(ret,formatstr,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,aa,ab,ac,ad,ae,0);
  1067. }
  1068. int sprintf(int ret,int formatstr,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,
  1069.                                    int a8,int a9,int aa,int ab,int ac,int ad){
  1070.     return sprintf(ret,formatstr,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,aa,ab,ac,ad,0,0);
  1071. }
  1072. int sprintf(int ret,int formatstr,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,
  1073.                                    int a8,int a9,int aa,int ab){
  1074.     return sprintf(ret,formatstr,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,aa,ab,0,0,0,0);
  1075. }
  1076. int sprintf(int ret,int formatstr,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,
  1077.                                    int a8,int a9,int aa){
  1078.     return sprintf(ret,formatstr,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,aa,0,0,0,0,0);
  1079. }
  1080. int sprintf(int ret,int formatstr,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,
  1081.                                    int a8,int a9){
  1082.     return sprintf(ret,formatstr,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,0,0,0,0,0,0);
  1083. }
  1084. int sprintf(int ret,int formatstr,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,
  1085.                                    int a8){
  1086.     return sprintf(ret,formatstr,a0,a1,a2,a3,a4,a5,a6,a7,a8,0,0,0,0,0,0,0);
  1087. }
  1088. int sprintf(int ret,int formatstr,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7){
  1089.     return sprintf(ret,formatstr,a0,a1,a2,a3,a4,a5,a6,a7,0,0,0,0,0,0,0,0);
  1090. }
  1091. int sprintf(int ret,int formatstr,int a0,int a1,int a2,int a3,int a4,int a5,int a6){
  1092.     return sprintf(ret,formatstr,a0,a1,a2,a3,a4,a5,a6,0,0,0,0,0,0,0,0,0);
  1093. }
  1094. int sprintf(int ret,int formatstr,int a0,int a1,int a2,int a3,int a4,int a5){
  1095.     return sprintf(ret,formatstr,a0,a1,a2,a3,a4,a5,0,0,0,0,0,0,0,0,0,0);
  1096. }
  1097. int sprintf(int ret,int formatstr,int a0,int a1,int a2,int a3,int a4){
  1098.     return sprintf(ret,formatstr,a0,a1,a2,a3,a4,0,0,0,0,0,0,0,0,0,0,0);
  1099. }
  1100. int sprintf(int ret,int formatstr,int a0,int a1,int a2,int a3){
  1101.     return sprintf(ret,formatstr,a0,a1,a2,a3,0,0,0,0,0,0,0,0,0,0,0,0);
  1102. }
  1103. int sprintf(int ret,int formatstr,int a0,int a1,int a2){
  1104.     return sprintf(ret,formatstr,a0,a1,a2,0,0,0,0,0,0,0,0,0,0,0,0,0);
  1105. }
  1106. int sprintf(int ret,int formatstr,int a0,int a1){
  1107.     return sprintf(ret,formatstr,a0,a1,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
  1108. }
  1109. int sprintf(int ret,int formatstr,int a0){
  1110.     return sprintf(ret,formatstr,a0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
  1111. }
  1112. int sprintf(int ret,int formatstr){
  1113.     return sprintf(ret,formatstr,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
  1114. }
  1115.  
  1116. void printf(int formatstr,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,
  1117.                           int a8,int a9,int aa,int ab,int ac,int ad,int ae){
  1118.     printf(formatstr,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,aa,ab,ac,ad,ae,0);
  1119. }
  1120. void printf(int formatstr,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,
  1121.                           int a8,int a9,int aa,int ab,int ac,int ad){
  1122.     printf(formatstr,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,aa,ab,ac,ad,0,0);
  1123. }
  1124. void printf(int formatstr,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,
  1125.                           int a8,int a9,int aa,int ab,int ac){
  1126.     printf(formatstr,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,aa,ab,ac,0,0,0);
  1127. }
  1128. void printf(int formatstr,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,
  1129.                           int a8,int a9,int aa,int ab){
  1130.     printf(formatstr,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,aa,ab,0,0,0,0);
  1131. }
  1132. void printf(int formatstr,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,
  1133.                           int a8,int a9,int aa){
  1134.     printf(formatstr,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,aa,0,0,0,0,0);
  1135. }
  1136. void printf(int formatstr,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,
  1137.                           int a8,int a9){
  1138.     printf(formatstr,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,0,0,0,0,0,0);
  1139. }
  1140. void printf(int formatstr,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,
  1141.                           int a8){
  1142.     printf(formatstr,a0,a1,a2,a3,a4,a5,a6,a7,a8,0,0,0,0,0,0,0);
  1143. }
  1144. void printf(int formatstr,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7){
  1145.     printf(formatstr,a0,a1,a2,a3,a4,a5,a6,a7,0,0,0,0,0,0,0,0);
  1146. }
  1147. void printf(int formatstr,int a0,int a1,int a2,int a3,int a4,int a5,int a6){
  1148.     printf(formatstr,a0,a1,a2,a3,a4,a5,a6,0,0,0,0,0,0,0,0,0);
  1149. }
  1150. void printf(int formatstr,int a0,int a1,int a2,int a3,int a4,int a5){
  1151.     printf(formatstr,a0,a1,a2,a3,a4,a5,0,0,0,0,0,0,0,0,0,0);
  1152. }
  1153. void printf(int formatstr,int a0,int a1,int a2,int a3,int a4){
  1154.     printf(formatstr,a0,a1,a2,a3,a4,0,0,0,0,0,0,0,0,0,0,0);
  1155. }
  1156. void printf(int formatstr,int a0,int a1,int a2,int a3){
  1157.     printf(formatstr,a0,a1,a2,a3,0,0,0,0,0,0,0,0,0,0,0,0);
  1158. }
  1159. void printf(int formatstr,int a0,int a1,int a2){
  1160.     printf(formatstr,a0,a1,a2,0,0,0,0,0,0,0,0,0,0,0,0,0);
  1161. }
  1162. void printf(int formatstr,int a0,int a1){
  1163.     printf(formatstr,a0,a1,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
  1164. }
  1165. void printf(int formatstr,int a0){
  1166.     printf(formatstr,a0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
  1167. }
  1168. void printf(int formatstr){
  1169.     printf(formatstr,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
  1170. }
  1171.  
  1172. void arrayset(int a,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,
  1173.                 int a8,int a9,int aa,int ab, int ac, int ad, int ae){
  1174.     a[0x0] = a0; a[0x1] = a1; a[0x2] = a2; a[0x3] = a3; a[0x4] = a4; a[0x5] = a5; a[0x6] = a6; a[0x7] = a7;
  1175.     a[0x8] = a8; a[0x9] = a9; a[0xa] = aa; a[0xb] = ab; a[0xc] = ac; a[0xd] = ad; a[0xe] = ae;
  1176. }
  1177. void arrayset(int a,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,
  1178.                 int a8,int a9,int aa,int ab, int ac, int ad){
  1179.     a[0x0] = a0; a[0x1] = a1; a[0x2] = a2; a[0x3] = a3; a[0x4] = a4; a[0x5] = a5; a[0x6] = a6; a[0x7] = a7;
  1180.     a[0x8] = a8; a[0x9] = a9; a[0xa] = aa; a[0xb] = ab; a[0xc] = ac; a[0xd] = ad;
  1181. }
  1182. void arrayset(int a,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,
  1183.                 int a8,int a9,int aa,int ab, int ac){
  1184.     a[0x0] = a0; a[0x1] = a1; a[0x2] = a2; a[0x3] = a3; a[0x4] = a4; a[0x5] = a5; a[0x6] = a6; a[0x7] = a7;
  1185.     a[0x8] = a8; a[0x9] = a9; a[0xa] = aa; a[0xb] = ab; a[0xc] = ac;
  1186. }
  1187. void arrayset(int a,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,
  1188.                 int a8,int a9,int aa,int ab){
  1189.     a[0x0] = a0; a[0x1] = a1; a[0x2] = a2; a[0x3] = a3; a[0x4] = a4; a[0x5] = a5; a[0x6] = a6; a[0x7] = a7;
  1190.     a[0x8] = a8; a[0x9] = a9; a[0xa] = aa; a[0xb] = ab;
  1191. }
  1192. void arrayset(int a,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,
  1193.                 int a8,int a9,int aa){
  1194.     a[0x0] = a0; a[0x1] = a1; a[0x2] = a2; a[0x3] = a3; a[0x4] = a4; a[0x5] = a5; a[0x6] = a6; a[0x7] = a7;
  1195.     a[0x8] = a8; a[0x9] = a9; a[0xa] = aa;
  1196. }
  1197. void arrayset(int a,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,
  1198.                 int a8,int a9){
  1199.     a[0x0] = a0; a[0x1] = a1; a[0x2] = a2; a[0x3] = a3; a[0x4] = a4; a[0x5] = a5; a[0x6] = a6; a[0x7] = a7;
  1200.     a[0x8] = a8; a[0x9] = a9;
  1201. }
  1202. void arrayset(int a,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,
  1203.                 int a8){
  1204.     a[0x0] = a0; a[0x1] = a1; a[0x2] = a2; a[0x3] = a3; a[0x4] = a4; a[0x5] = a5; a[0x6] = a6; a[0x7] = a7;
  1205.     a[0x8] = a8;
  1206. }
  1207. void arrayset(int a,int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7){
  1208.     a[0x0] = a0; a[0x1] = a1; a[0x2] = a2; a[0x3] = a3; a[0x4] = a4; a[0x5] = a5; a[0x6] = a6; a[0x7] = a7;
  1209. }
  1210. void arrayset(int a,int a0,int a1,int a2,int a3,int a4,int a5,int a6){
  1211.     a[0x0] = a0; a[0x1] = a1; a[0x2] = a2; a[0x3] = a3; a[0x4] = a4; a[0x5] = a5; a[0x6] = a6;
  1212. }
  1213. void arrayset(int a,int a0,int a1,int a2,int a3,int a4,int a5){
  1214.     a[0x0] = a0; a[0x1] = a1; a[0x2] = a2; a[0x3] = a3; a[0x4] = a4; a[0x5] = a5;
  1215. }
  1216. void arrayset(int a,int a0,int a1,int a2,int a3,int a4){
  1217.     a[0x0] = a0; a[0x1] = a1; a[0x2] = a2; a[0x3] = a3; a[0x4] = a4;
  1218. }
  1219. void arrayset(int a,int a0,int a1,int a2,int a3){
  1220.     a[0x0] = a0; a[0x1] = a1; a[0x2] = a2; a[0x3] = a3;
  1221. }
  1222. void arrayset(int a,int a0,int a1,int a2){
  1223.     a[0x0] = a0; a[0x1] = a1; a[0x2] = a2;
  1224. }
  1225. void arrayset(int a,int a0,int a1){
  1226.     a[0x0] = a0; a[0x1] = a1;
  1227. }
  1228. void arrayset(int a,int a0){
  1229.     a[0x0] = a0;
  1230. }
  1231.  
  1232.  
  1233. int ReturnStringCharPos(int str, int chr)
  1234. {
  1235.     int sz = strlen(str-1);
  1236.     for ( int q = 0; q <= sz; ++q ) {
  1237.         int a = str[q];
  1238.         if ( a == chr ) return q;
  1239.     }
  1240. }
  1241.  
  1242. int ReturnStringCharPos(int str, int pos, int chr)
  1243. {
  1244.     int sz = strlen(str-1);
  1245.     for ( int q = 0; q <= sz; ++q ) {
  1246.         int a = str[q];
  1247.         if ( a == chr ) return q;
  1248.     }
  1249. }
  1250.  
  1251. int ReturnStringCharPosRev(int str, int chr)
  1252. {
  1253.     int sz = strlen(str-1);
  1254.     for ( int q = sz; q >= 0; --q ) {
  1255.         int a = str[q];
  1256.         if ( a == chr ) return q;
  1257.     }
  1258. }
  1259.  
  1260. int ReturnStringCharPosRev(int str, int pos, int chr)
  1261. {
  1262.     int sz = strlen(str-1);
  1263.     for ( int q = pos; q >= 0; --q ) {
  1264.         int a = str[q];
  1265.         if ( a == chr ) return q;
  1266.     }
  1267. }
  1268.  
  1269. int IsChar(int chr) { return chr; }
  1270. bool IsChar(int chr, int comp) { return (chr == comp); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement