19 March 2018 09:54:14 AM CHRPAK_TEST: 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 CH_CAP_TEST CH_CAP uppercases a character. C CH_CAP(C) F F f F 1 1 b B B B CH_COUNT_FILE_ADD_TEST 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.11124 2812 19.9506 10976 ! 0.0599826 33 " 3.01367 1658 # 0.0527119 29 $ 0.00727061 4 % 0.00545296 3 & 0.0254471 14 ' 0.359895 198 ( 0.803403 442 ) 0.803403 442 * 14.1195 7768 + 0.139959 77 , 0.425331 234 - 0.645267 355 . 0.350807 193 / 3.59895 1980 0 0.656173 361 1 0.556202 306 2 0.498037 274 3 0.214483 118 4 0.247201 136 5 0.199942 110 6 0.105424 58 7 0.089065 49 8 0.252654 139 9 0.161771 89 : 0.507125 279 ; 1.93035 1062 < 3.35175 1844 = 0.494402 272 > 0.0436237 24 ? 0.0236295 13 @ 0.00727061 4 A 0.399884 220 B 0.261742 144 C 0.292642 161 D 0.187218 103 E 0.539843 297 F 0.0527119 29 G 0.312636 172 H 0.203577 112 I 0.447143 246 J 0.156318 86 K 0.0327178 18 L 0.439872 242 M 0.223571 123 N 0.383525 211 O 0.32536 179 P 0.254471 140 Q 0.0145412 8 R 0.243566 134 S 0.830667 457 T 1.1124 612 U 0.256289 141 V 0.0163589 9 W 0.0690708 38 X 0.0599826 33 Y 0.0254471 14 Z 0.00363531 2 [ 0.105424 58 \ 1.05424 580 ] 0.105424 58 ^ 0.00727061 4 _ 2.01759 1110 a 1.15784 637 b 0.370801 204 c 2.0903 1150 d 1.3178 725 e 2.81918 1551 f 0.416243 229 g 0.579831 319 h 0.897921 494 i 2.63014 1447 j 0.0399884 22 k 0.170859 94 l 0.559837 308 m 0.181765 100 n 2.5429 1399 o 2.29024 1260 p 0.367166 202 q 0.0254471 14 r 1.97215 1085 s 3.11 1711 t 4.12971 2272 u 1.80311 992 v 0.319907 176 w 0.221754 122 x 0.0872473 48 y 0.161771 89 z 0.0181765 10 { 0.23266 128 | 0.00545296 3 } 0.23266 128 CH_INDEX_FIRST_TEST 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. CH_INDEX_LAST_TEST 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. CH_IS_DIGIT_TEST CH_IS_DIGIT is TRUE if a character represents a digit. C CH_IS_DIGIT(C) '0' 1 '1' 1 '2' 1 '3' 1 '4' 1 '5' 1 '6' 1 '7' 1 '8' 1 '9' 1 'X' 0 '?' 0 ' ' 0 CH_IS_ISBN_DIGIT_TEST CH_IS_ISBN_DIGIT is TRUE if a character represents an ISBN digit. C CH_IS_ISBN_DIGIT(C) '0' 1 '1' 1 '2' 1 '3' 1 '4' 1 '5' 1 '6' 1 '7' 1 '8' 1 '9' 1 'X' 1 'x' 1 'Y' 0 '*' 0 '?' 0 ' ' 0 CH_LOW_TEST CH_LOW lowercases a character. C CH_LOW(C) F f f f 1 1 b b B b CH_PAD_TEST 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!" CH_TO_DIGIT_TEST CH_TO_DIGIT: character -> decimal digit 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 X -1 11 ? -1 12 -1 CH_TO_ROT13_TEST 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. CH_UNIFORM_TEST 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 S_LAST_CH_TEST5 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 DIGIT_TO_CH_TEST DIGIT_TO_CH: character -> decimal 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 * -1 11 * -1 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 I4_TO_ISBN_DIGIT_TEST I4_TO_ISBN_DIGIT converts digits 0 to 10 to an ISBN digit. 0 '0' 1 '1' 2 '2' 3 '3' 4 '4' 5 '5' 6 '6' 7 '7' 8 '8' 9 '9' 10 'X' I4_TO_MONTH_ABB_TEST 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" I4_TO_UNARY_TEST I4_TO_UNARY converts an integer to unary. I4 I4_TO_UNARY(I4) -5 "-11111" 0 "0" 7 "1111111" ISBN_DIGIT_TO_I4_TEST ISBN_DIGIT_TO_I4 converts an ISBN digit to an I4 '0' 0 '1' 1 '2' 2 '3' 3 '4' 4 '5' 5 '6' 6 '7' 7 '8' 8 '9' 9 'X' 10 'x' 10 'Y' -1 '*' -1 '?' -1 ' ' -1 S_ADJUSTL_TEST S_ADJUSTL justifies a string to the left; Original S_ADJUSTL ---------- ---------- " Hello! " "Hello! " "Ouch! " "Ouch! " " A B C " "A B C " S_BEGIN_TEST 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 S_DIGITS_COUNT_TEST S_DIGITS_COUNT counts the digits in a string. We count 7 digits in '34E94-70.6' We count 0 digits in 'Not a one!' We count 3 digits in '!8*k >>>> & SEVEN-0.3' S_EQI_TEST 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 S_ESCAPE_TEX_TEST 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 S_LAST_CH_TEST 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" S_LEN_TRIM_TEST 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 S_REPLACE_CH_TEST S_REPLACE_CH replaces one character by another; C1 C2 Original String Modified String n t No pennies now. No petties tow. S_REVERSE_TEST S_REVERSE reverses a string. Before: "A man, a plan, a canal, Panama!". After: "!amanaP ,lanac a ,nalp a ,nam A". S_S_SUBANAGRAM_TEST 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 S_SCRABBLE_POINTS_TEST 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 S_SORT_A_TEST 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" S_SUBSTRING_TEST 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 S_TO_CAESAR_TEST S_TO_CAESAR applies a Caesar Shift cipher to a string. S2 = S_TO_CAESAR ( S1, K ), varying K. K ---------------S1---------------- ---------------S2---------------- -5 'A man, a plan, a canal: Panama!' 'V hvi, v kgvi, v xvivg: Kvivhv!' -4 'A man, a plan, a canal: Panama!' 'W iwj, w lhwj, w ywjwh: Lwjwiw!' -3 'A man, a plan, a canal: Panama!' 'X jxk, x mixk, x zxkxi: Mxkxjx!' -2 'A man, a plan, a canal: Panama!' 'Y kyl, y njyl, y aylyj: Nylyky!' -1 'A man, a plan, a canal: Panama!' 'Z lzm, z okzm, z bzmzk: Ozmzlz!' 0 'A man, a plan, a canal: Panama!' 'A man, a plan, a canal: Panama!' 1 'A man, a plan, a canal: Panama!' 'B nbo, b qmbo, b dbobm: Qbobnb!' 2 'A man, a plan, a canal: Panama!' 'C ocp, c rncp, c ecpcn: Rcpcoc!' 3 'A man, a plan, a canal: Panama!' 'D pdq, d sodq, d fdqdo: Sdqdpd!' 4 'A man, a plan, a canal: Panama!' 'E qer, e tper, e gerep: Tereqe!' 5 'A man, a plan, a canal: Panama!' 'F rfs, f uqfs, f hfsfq: Ufsfrf!' S2 = S_TO_CAESAR ( S1, K ). S3 = S_TO_CAESAR ( S2, -K ) K ------------S1------------ ------------S2------------ ------------S3------------ -5 'The key is under the mat' 'Ocz fzt dn piyzm ocz hvo' 'The key is under the mat' -4 'The key is under the mat' 'Pda gau eo qjzan pda iwp' 'The key is under the mat' -3 'The key is under the mat' 'Qeb hbv fp rkabo qeb jxq' 'The key is under the mat' -2 'The key is under the mat' 'Rfc icw gq slbcp rfc kyr' 'The key is under the mat' -1 'The key is under the mat' 'Sgd jdx hr tmcdq sgd lzs' 'The key is under the mat' 0 'The key is under the mat' 'The key is under the mat' 'The key is under the mat' 1 'The key is under the mat' 'Uif lfz jt voefs uif nbu' 'The key is under the mat' 2 'The key is under the mat' 'Vjg mga ku wpfgt vjg ocv' 'The key is under the mat' 3 'The key is under the mat' 'Wkh nhb lv xqghu wkh pdw' 'The key is under the mat' 4 'The key is under the mat' 'Xli oic mw yrhiv xli qex' 'The key is under the mat' 5 'The key is under the mat' 'Ymj pjd nx zsijw ymj rfy' 'The key is under the mat' S_TO_DIGITS_TEST S_TO_DIGITS: string -> digit vector Test string: '34E94-70.6' Extracted 5 digits: 1 3 2 4 3 9 4 4 5 7 Test string: '34E94-70.6' Extracted 7 digits: 1 3 2 4 3 9 4 4 5 7 6 0 7 6 S_TO_FORMAT_TEST 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 S_TO_ISBN_DIGITS_TEST S_TO_ISBN_DIGITS: string -> ISBN digit vector Test string: '34E9X-70.6' Extracted 5 digits: 1 3 2 4 3 9 4 10 5 7 Test string: '34E9X-70.6' Extracted 7 digits: 1 3 2 4 3 9 4 10 5 7 6 0 7 6 S_TO_ROT13_TEST 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 S_WORD_COUNT_TEST 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 S_WORD_EXTRACT_FIRST_TEST 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. WORD_NEXT_READ_TEST 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_TEST: Normal end of execution. 19 March 2018 09:54:14 AM