21 October 2014 09:57:02 AM CHRPAK_PRB: C++ version Test the CHRPAK library. PRINT_SIZES: Report data type sizes. (Min/Max data currently unavailable... Type Size Min Max bool 1 char 1 unsigned char 1 short int 2 unsigned short int 2 int 4 unsigned int 4 long int 8 unsigned long int 8 long long int 8 unsigned long long int 8 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.2884 2360 20.7995 9282 ! 0.0694662 31 " 3.26267 1456 # 0.0649845 29 $ 0.00896338 4 % 0.00672254 3 & 0.0313718 14 ' 0.112042 50 ( 0.833595 372 ) 0.833595 372 * 14.3302 6395 + 0.141173 63 , 0.358535 160 - 0.461614 206 . 0.365258 163 / 3.67051 1638 0 0.878412 392 1 0.898579 401 2 0.71483 319 3 0.230807 103 4 0.221844 99 5 0.360776 161 6 0.136692 61 7 0.118765 53 8 0.282347 126 9 0.230807 103 : 0.515395 230 ; 1.99659 891 < 3.5383 1579 = 0.50195 224 > 0.0358535 16 ? 0.0201676 9 @ 0.00896338 4 A 0.360776 161 B 0.233048 104 C 0.21064 94 D 0.10532 47 E 0.495227 221 F 0.0425761 19 G 0.246493 110 H 0.161341 72 I 0.23753 106 J 0.163582 73 K 0.0268902 12 L 0.448169 200 M 0.233048 104 N 0.338368 151 O 0.242011 108 P 0.257697 115 Q 0.0134451 6 R 0.199435 89 S 0.643123 287 T 0.970286 433 U 0.250975 112 V 0.0134451 6 W 0.0605028 27 X 0.0425761 19 Y 0.0224085 10 Z 0.00448169 2 [ 0.103079 46 \ 1.163 519 ] 0.103079 46 ^ 0.00896338 4 _ 1.0039 448 a 1.13835 508 b 0.338368 151 c 2.03469 908 d 1.19437 533 e 2.82123 1259 f 0.441447 197 g 0.519876 232 h 0.887375 396 i 2.41563 1078 j 0.0515395 23 k 0.161341 72 l 0.566934 253 m 0.168063 75 n 2.57697 1150 o 2.30135 1027 p 0.36974 165 q 0.0268902 12 r 2.00332 894 s 3.03411 1354 t 4.06041 1812 u 1.88007 839 v 0.284587 127 w 0.221844 99 x 0.0649845 29 y 0.18599 83 z 0.0246493 11 { 0.242011 108 | 0.00672254 3 } 0.242011 108 TEST014 CH_INDEX_FIRST 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!" TEST022 HEX_DIGIT_TO_I4: hexadecimal digit -> I4, I4_TO_HEX_DIGIT: I4 -> hexadecimal digit. -2 '*' -1 -1 '*' -1 0 '0' 0 1 '1' 1 2 '2' 2 3 '3' 3 4 '4' 4 5 '5' 5 6 '6' 6 7 '7' 7 8 '8' 8 9 '9' 9 10 'a' 10 11 'b' 11 12 'c' 12 13 'd' 13 14 'e' 14 15 'f' 15 16 '*' -1 17 '*' -1 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 TEST11255 CHARSTAR_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 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. S1: "Look for the lily in the field." S2: "Look for" SBEGIN ( S1, S2 ) = 1 S1: "Look for" S2: "Look for the lily in the field." SBEGIN ( S1, S2 ) = 0 S1: "Look for the lily in the field." S2: "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 !! !" TEST094 S_CAP capitalizes all characters in a string; S_LOW lowercases all characters; S_WORD_CAP initial-capitalizes words in a string; ------Original------ -----Capitalized----------Lower Cased----- -----Word_Caps----- "HELLO World !! ! " "HELLO WORLD !! ! " "hello world !! ! " "Hello World !! ! " "12345678901234567890" "12345678901234567890" "12345678901234567890" "12345678901234567890" "Abc Def Ghi Jkl Mno " "ABC DEF GHI JKL MNO " "abc def ghi jkl mno " "Abc Def Ghi Jkl Mno " "!@#$%a^&A(){}[]\|<>?" "!@#$%A^&A(){}[]\|<>?" "!@#$%a^&a(){}[]\|<>?" "!@#$%a^&a(){}[]\|<>?" "it is time to turn the page." "IT IS TIME TO TURN THE PAGE." "it is time to turn the page." "It Is Time To Turn The Page." TEST0975 S_CH_COUNT counts occurrences of a character. String = "Bob is debobbing the bobber!". Character is "b". Number of occurrences = 7 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 character 'l' first occurs in position 13. 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 CH_INDEX_LAST reports the LAST occurrence of a character. String = The quick brown fox jumps right over the big lazy dog! C J a 46 b 41 c 7 d 50 e 39 f 16 g 52 h 38 i 42 j 20 k 8 l 45 m 22 n 14 o 51 p 23 q 4 r 35 s 24 t 37 u 21 v 33 w 13 x 18 y 48 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 TEST1227 S_SCRABBLE_POINTS returns the value of a string as a Scrabble word. I ----S------- Value 1 January 17 2 February 16 3 March 12 4 April 7 5 May 8 6 June 11 7 July 14 8 August 7 9 September 15 10 October 11 11 November 15 12 December 15 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 TEST132 S_TO_ROT13 encrypts a string. Original: abcdefghijklmnopqrstuvwxyz Rotated once: nopqrstuvwxyzabcdefghijklm Rotated twice: abcdefghijklmnopqrstuvwxyz Original: Cher Rotated once: Pure Rotated twice: Cher Original: James Thurston Howell Rotated once: Wnzrf Guhefgba Ubjryy Rotated twice: James Thurston Howell 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" "an" "incontrovertible" "sample" "of" "text!" 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. 21 October 2014 09:57:02 AM