27 October 2007 11:58:19 AM CHRPAK_PRB: C++ version Test the routines in the CHRPAK library. PRINT_SIZES: Report data type sizes. (Min/Max data currently unavailable... Type Size Min Max bool 4 char 1 unsigned char 1 0 short int 2 unsigned short int 2 0 int 4 unsigned int 4 0 long int 4 unsigned long int 4 0 float 4 double 8 TEST001 A_TO_I4: Alphabetic character => I I4_TO_A: I => Alphabetic character 1:26 = A:Z 27:52 = a:z I ==> A ==> I 0 ' ' 0 3 'C' 3 6 'F' 6 9 'I' 9 12 'L' 12 15 'O' 15 18 'R' 18 21 'U' 21 24 'X' 24 27 'a' 27 30 'd' 30 33 'g' 33 36 'j' 36 39 'm' 39 42 'p' 42 45 's' 45 48 'v' 48 51 'y' 51 54 ' ' 0 TEST0055 INT_TO_BYTE converts an unsigned int to a string, BYTE_TO_INT converts it back. IVAL Recovered IVAL 3 3 1952 1952 123456789 123456789 TEST011 CH_CAP uppercases a character. C CH_CAP(C) F F f F 1 1 b B B B TEST012 CH_COUNT_FILE_ADD adds the characters in a file to a character count. DEBUG, call C_COUNT_INIT: DEBUG, call C_COUNT_FILE_ADD: DEBUG, call C_COUNT_PRINT: Raw character count data: Char Percent Count # 10 5.1968 1958 21.4109 8067 ! 0.0716618 27 " 3.69987 1394 # 0.0557369 21 $ 0.00796242 3 % 0.00530828 2 & 0.07697 29 ' 0.12209 46 ( 1.07227 404 ) 1.07227 404 * 14.5898 5497 + 0.135361 51 , 0.501632 189 - 0.392813 148 . 0.27603 104 / 2.96202 1116 0 0.992648 374 1 0.997956 376 2 0.727234 274 3 0.212331 80 4 0.257451 97 5 0.38485 145 6 0.180481 68 7 0.145978 55 8 0.302572 114 9 0.19906 75 : 0.437933 165 ; 2.17109 818 < 4.19619 1581 = 0.437933 165 > 0.0318497 12 ? 0.0212331 8 @ 0.00796242 3 A 0.345038 130 B 0.244181 92 C 0.207023 78 D 0.106166 40 E 0.496324 187 F 0.0451204 17 G 0.0557369 21 H 0.156594 59 I 0.228256 86 J 0.204369 77 K 0.0318497 12 L 0.167211 63 M 0.220294 83 N 0.238873 90 O 0.228256 86 P 0.161902 61 Q 0.0159248 6 R 0.193752 73 S 0.634339 239 T 0.844016 318 U 0.148632 56 V 0.0132707 5 W 0.0557369 21 X 0.0398121 15 Y 0.0265414 10 Z 0.00530828 2 [ 0.167211 63 \ 1.35892 512 ] 0.167211 63 ^ 0.00796242 3 _ 1.04838 395 a 1.30584 492 b 0.23091 87 c 2.04103 769 d 1.0245 386 e 2.26133 852 f 0.445895 168 g 0.310534 117 h 0.777663 293 i 1.95345 736 j 0.0583911 22 k 0.164557 62 l 0.491016 185 m 0.161902 61 n 2.28521 861 o 2.59044 976 p 0.459166 173 q 0.0291955 11 r 2.01715 760 s 2.72846 1028 t 3.98917 1503 u 1.7942 676 v 0.483053 182 w 0.326459 123 x 0.0530828 20 y 0.318497 120 z 0.018579 7 { 0.228256 86 | 0.00530828 2 } 0.228256 86 TEST014 CH_INDEX searches a string for a character. The test string, in quotes: "Joel prefers graphics to graphs." The first occurrence of 'g' is at index 13. TEST015 CH_INDEX_LAST finds the last occurrence of a character. The test string, in quotes: "HELLO World, how ARE you?" Last occurrence of o is at 22. TEST016 CH_LOW lowercases a character. C CH_LOW(C) F f f f 1 1 b b B b TEST0175 CH_PAD places spaces around a character. The string is : "I vant to be alone!" We will try to place spaces around the A in ALONE. The string is : "I vant to be a lone!" TEST026 CH_TO_ROT13 "encodes" a character using ROT13. CH :ABCDEFGHIJKLMNOPQRSTUVQXYZ ROT13(CH) :NOPQRSTUVWXYZABCDEFGHIDKLM ROT13(ROT13(CH)):ABCDEFGHIJKLMNOPQRSTUVQXYZ CH : CH_TO_ROT13 "encodes" a character using ROT13. ROT13(CH) : PU_GB_EBG68 "rapbqrf" n punenpgre hfvat EBG68. ROT13(ROT13(CH)): CH_TO_ROT13 "encodes" a character using ROT13. TEST029 CH_UNIFORM returns a random character. I A Count 1 A 0 2 B 0 3 C 0 4 D 5327 5 E 5277 6 F 5131 7 G 5174 8 H 5331 9 I 5352 10 J 5334 11 K 5279 12 L 5266 13 M 5173 14 N 5428 15 O 5316 16 P 5279 17 Q 5226 18 R 5235 19 S 5221 20 T 5279 21 U 5289 22 V 5083 23 W 0 24 X 0 25 Y 0 26 Z 0 TEST0545 I4_TO_MONTH_ABB returns the name of the I-th month. I Month 0 ??? 1 Jan 2 Feb 3 Mar 4 Apr 5 May 6 Jun 7 Jul 8 Aug 9 Sep 10 Oct 11 Nov 12 Dec TEST058 I4_TO_S: int -> string; S_TO_I4: string -> I4. " 0" 0 " 0" " 9" 9 " 9" " 10" 10 " 10" " 11" 11 " 11" " -124 56 AbC" -124 " -124" " 25,50,5" 25 " 25" " +15.9" 15 " 15" " 123abc" 123 " 123" TEST065 I4_TO_UNARY converts an integer to unary. I4 I4_TO_UNARY(I4) -5 '-11111' 0 '0' 7 '1111111' TEST085 S_ADJUSTL justifies a string to the left; Original S_ADJUSTL ---------- ---------- " Hello! " "Hello!" "Ouch!" "Ouch!" " A B C " "A B C" TEST090 S_BEGIN is true if string 1 begins with string 2. String 1: "Look for the lily in the field." String2: "Look for" SBEGIN ( S1, S2 ) = 1 String 1: "Look for" String2: "Look for the lily in the field." SBEGIN ( S1, S2 ) = 0 String 1: "Look for the lily in the field." String2: "Look out!" SBEGIN ( S1, S2 ) = 0 TEST091 S_BEHEAD_SUBSTRING removes an initial substring from a string, if it occurs. ------String-------- -----SUB------------ ---Beheaded---- HELLO World! HELLO World! 12345678901234567890 12345 678901234567890 0.314159E+01 314 0.314159E+01 !@#$%a^&A(){}[]\|<>? !@#$%a^&A(){}[]\|<>? TEST093 S_BLANKS_DELETE removes double blanks. Original string: " HELLO World !! ! " After S_BLANKS_DELETE: "HELLO World !! ! " TEST1015 S_EQI reports if two strings are equal, ignoring case. String 1: "HELLO" String2: "HeLLO" S_EQI(S1,S2) = 1 String 1: "HELP ME" String2: "HELP" S_EQI(S1,S2) = 0 TEST102 S_ESCAPE_TEX "protects" characters in a string that might otherwise be interpreted as TeX escape characters. Original string: "The file A_B.TXT is {I think__so} of size 2^8 or C\B.". De-escaped string: "The file A\_B.TXT is \{I think\_\_so\} of size 2\^8 or C\\B.". TEST1035 S_FIRST_CH finds the first occurrence of a character. The test string, in quotes: "Look for the lily in the field." The string, starting with the first occurrence of 'l': "lily in the field." TEST1036 S_FIRST_NONBLANK finds a pointer to the first nonblank character in a string. The test string, in quotes: " HELLO World, how ARE you?" The string shifted left, using the pointer: "HELLO World, how ARE you?" TEST105 S_INC_C can "increment" the characters in a string. Starting string: "Tax" Incremented forms: Tay Taz Tba Tbb Tbc Starting string: "aB34c* 8zY" Incremented forms: aB34c* 8zZ aB34d* 8aA aB34d* 8aB aB34d* 8aC aB34d* 8aD TEST109 S_INDEX_LAST_C reports the LAST occurrence of a character. String = The quick brown fox jumps right over the big lazy dog! I C J 27 a 46 28 b 41 29 c 7 30 d 50 31 e 39 32 f 16 33 g 52 34 h 38 35 i 42 36 j 20 37 k 8 38 l 45 39 m 22 40 n 14 41 o 51 42 p 23 43 q 4 44 r 35 45 s 24 46 t 37 47 u 21 48 v 33 49 w 13 50 x 18 51 y 48 52 z 47 TEST1125 S_LAST_CH finds the last occurrence of a character. The test string, in quotes: "Look for last . in file_name.cpp" The string, starting with the last occurrence of '.': ".cpp" TEST1126 S_LEN_TRIM reports the length of a string to the last nonblank. Here are some strings, and their lengths: "HELLO" 5 " B la nk" 9 " " 0 "1234567890" 10 TEST115 S_REPLACE_CH replaces one character by another; C1 C2 Original String Modified String n t No pennies now. No petties tow. TEST119 S_REVERSE reverses a string. Before: "A man, a plan, a canal, Panama!". After: "!amanaP ,lanac a ,nalp a ,nam A". TEST1225 S_S_SUBANAGRAM is TRUE if S2 is a "subanagram" of S1. "Get a priest!" "stripe" 1 "Get a priest!" "pastor" 0 "Get a priest!" "a sip" 1 "Get a priest!" "tag!" 0 TEST1255 S_SORT_A ascending sorts a string. -------String------- -------Sorted------- "HELLO World !! ! " " !!!EHLLOWdlor" "12345678901234567890" "00112233445566778899" "Abc Def Ghi Jkl Mno " " ADGJMbcefhiklno" "AbleBakerCharlieDelt" "ABCDaabeeeehiklllrrt" "What? You have seen?" " ??WYaaeeehhnostuv" TEST1265 S_SUBSTRING returns a substring of a given string. S A B S(A:B) -------------------- -- -- ---------- abcdefghijklmnopqrts 6 10 fghij abcdefghijklmnopqrts 15 15 o abcdefghijklmnopqrts 17 20 qrts TEST129 S_TO_FORMAT, string -> FORTRAN format RcW.M; --------String------ R c W M a80 1 a 80 0 f8.4 1 f 8 4 3g14.6 3 g 14 6 i12 1 i 12 0 12l1 12 l 1 0 (10o11) 10 o 11 0 ( 5 z 11.7 ) 5 z 11 7 TEST137 S_WORD_COUNT counts the words in a string STRING Words ? 1 A man, a plan, a canal - Panama! 8 justone!word,-@#$ 1 How about a day in the park? 7 TEST138 S_WORD_EXTRACT_FIRST extracts the first word from a string. Our input string is: "Just an incontrovertible sample of text!". "Just" "ans " "incontrovertible" "sample" "ofm le" "text!e " Reached the last word. TEST154 WORD_NEXT_READ returns each word from a string. It pays attention to various parentheses and brackets. We use the following string: " Here is a string, (you see) with x[1] = {gamma}!". Here are the individual words: 1 "Here". 2 "is". 3 "a". 4 "string". 5 "(". 6 "you". 7 "see". 8 ")". 9 "with". 10 "x". 11 "[". 12 "1". 13 "]". 14 "=". 15 "{". 16 "gamma". 17 "}". 18 "!". Number of words was 18 CHRPAK_PRB: Normal end of execution. 27 October 2007 11:58:20 AM