CHRPAK
Strings and Characters
CHRPAK
is a C library which
can handle characters and strings.
CHRPAK began when I simply wanted to be able to capitalize
a string. Now it has expanded to a number of interesting uses.
Many unusual situations are provided for, including
-
string '31.2' <=> numeric value 31.2;
-
uppercase <=> lowercase;
-
removal of control characters or blanks;
-
sorting, merging, searching.
Many of the routine names begin with the name of the data type they
operate on:
-
B4 - a 4 byte word;
-
CH - a character;
-
CHVEC - a vector of characters;
-
DEC - a decimal fraction;
-
DIGIT - a character representing a numeric digit;
-
I4 - an integer;
-
R4 - a real;
-
R8 - a double precision real;
-
RAT - a ratio I/J;
-
S - a string;
-
SVEC - a vector of strings;
-
SVECI - a vector of strings, implicitly capitalized;
Licensing:
The computer code and data files described and made available on this web page
are distributed under
the GNU LGPL license.
Languages:
CHRPAK is available in
a C version and
a C++ version and
a FORTRAN90 version and
a MATLAB version and
a Python version.
Related Software and Data:
CAESAR,
a C library which
can apply a Caesar Shift Cipher to a string of text.
ROT13,
a C program which
makes a copy of a file which has
been encoded using the ROT13 coding, and a ROT5 coding for digits.
Reference:
-
Carl Branden, John Tooze,
Introduction to Protein Structure,
Second Edition,
Garland Publishing, 1999,
ISBN: 0815323050,
LC: QP551.B7635.
-
Paul Bratley, Bennett Fox, Linus Schrage,
A Guide to Simulation,
Second Edition,
Springer, 1987,
ISBN: 0387964673,
LC: QA76.9.C65.B73.
-
IEEE Standards Committee 754,
IEEE Standard for Binary Floating Point Arithmetic,
ANSI/IEEE Standard 754-1985,
SIGPLAN Notices,
Volume 22, Number 2, 1987, pages 9-25.
-
Donald Knuth,
The Art of Computer Programming,
Volume 3, Sorting and Searching,
Second Edition,
Addison Wesley, 1998,
ISBN: 0201896850,
LC: QA76.6.K64.
-
Albert Nijenhuis, Herbert Wilf,
Combinatorial Algorithms for Computers and Calculators,
Academic Press, 1978,
ISBN: 0-12-519260-6,
LC: QA164.N54.
Source Code:
Examples and Tests:
List of Routines:
-
A_TO_I4 returns the index of an alphabetic character.
-
BASE_TO_I4 returns the value of an integer represented in some base.
-
BYTE_TO_INT converts 4 bytes into an unsigned integer.
-
CH_CAP capitalizes a single character.
-
CH_COUNT_CVEC_ADD adds a character vector to a character count.
-
CH_EQI is TRUE (1) if two characters are equal, disregarding case.
-
CH_INDEX_FIRST finds the first occurrence of a character in a string.
-
CH_INDEX_LAST finds the last occurrence of a character in a string.
-
CH_IS_ALPHA is TRUE if a charaacter is alphabetic.
-
CH_IS_ALPHANUMERIC is TRUE if a character is alphanumeric.
-
CH_IS_CONTROL is TRUE if a character is a control character.
-
CH_IS_DIGIT returns TRUE if a character is a decimal digit.
-
CH_IS_LOWER is TRUE if C is a lowercase alphabetic character.
-
CH_IS_SPACE is TRUE if a character represents "white space".
-
CH_LOW lowercases a single character.
-
CH_READ reads one character from a binary file.
-
CH_ROMAN_TO_I4 returns the integer value of a single Roman digit.
-
CH_SCRABBLE returns the character on a given Scrabble tile.
-
CH_SCRABBLE_FREQUENCY returns the Scrabble frequency of a character.
-
CH_SCRABBLE_POINTS returns the Scrabble point value of a character.
-
CH_SCRABBLE_SELECT selects a character with the Scrabble probability.
-
CH_SWAP swaps two characters.
-
CH_TO_DIGIT returns the integer value of a base 10 digit.
-
CH_TO_DIGIT_BIN returns the integer value of a binary digit.
-
CH_TO_ROT13 converts a character to its ROT13 equivalent.
-
CH_TO_SCRABBLE returns the Scrabble index of a character.
-
CH_UNIFORM returns a random character in a given range.
-
DIGIT_INC increments a decimal digit.
-
DIGIT_TO_CH returns the character representation of a decimal digit.
-
HEX_DIGIT_TO_I4 converts a hexadecimal digit to an I4.
-
I4_HUGE returns a "huge" I4.
-
I4_LOG_10 returns the integer part of the logarithm base 10 of an I4.
-
I4_MAX returns the maximum of two I4's.
-
I4_MIN returns the smaller of two I4's.
-
I4_SWAP switches two I4's.
-
I4_TO_A returns the I-th alphabetic character.
-
I4_TO_AMINO_CODE converts an integer to an amino code.
-
I4_TO_HEX_DIGIT converts a (small) I4 to a hexadecimal digit.
-
I4_TO_ISBN converts an I4 to an ISBN digit.
-
I4_TO_MONTH_ABB returns an abbreviated month name.
-
I4_TO_MONTH_NAME returns a month name.
-
I4_TO_S converts an I4 to a string.
-
I4_UNIFORM returns a scaled pseudorandom I4.
-
ISBN_TO_I4 converts an ISBN character into an I4.
-
R4_NINT returns the nearest integer to an R4.
-
R8_UNIFORM_01 returns a unit pseudorandom R8.
-
S_ADJUSTL flushes a string left.
-
S_BEGIN reports whether string 1 begins with string 2.
-
S_BLANK_DELETE removes blanks and left justifies the remainder.
-
S_BLANKS_DELETE replaces consecutive blanks by one blank.
-
S_CAP capitalizes all the characters in a string.
-
S_CAT concatenates two strings to make a third string.
-
S_CH_COUNT counts occurrences of a particular character in a string.
-
S_CH_DELETE removes all occurrences of a character from a string.
-
S_CONTROL_BLANK replaces control characters with blanks.
-
S_EQI reports whether two strings are equal, ignoring case.
-
S_ESCAPE_TEX de-escapes TeX escape sequences.
-
S_FIRST_CH points to the first occurrence of a character in a string.
-
S_FIRST_NONBLANK points to the first nonblank character in a string.
-
S_INDEX_LAST_C points to the last occurrence of a given character.
-
S_LEN_TRIM returns the length of a string to the last nonblank.
-
S_LOW replaces all uppercase characters by lowercase ones.
-
S_NEWLINE_TO_NULL replaces carriage returns or newlines by nulls.
-
S_REPLACE_CH replaces all occurrences of one character by another.
-
S_REVERSE reverses the characters in a string.
-
S_SCRABBLE_POINTS returns the Scrabble point value of a string.
-
S_SORT_A sorts a string into ascending order.
-
S_SUBSTRING returns a substring of a given string.
-
S_TO_I4 reads an I4 from a string.
-
S_TO_I4VEC reads an I4VEC from a string.
-
S_TO_L4 reads an L4 from a string.
-
S_TO_R4 reads an R4 value from a string.
-
S_TO_R4VEC reads an R4VEC from a string.
-
S_TO_R8 reads an R8 value from a string.
-
S_TO_R8VEC reads an R8VEC from a string.
-
S_TO_ROT13 "rotates" the alphabetical characters in a string by 13 positions.
-
S_TRIM promotes the final null forward through trailing blanks.
-
S_WORD_CAP capitalizes the first character of each word in a string.
-
S_WORD_COUNT counts the number of "words" in a string.
-
S_WORD_EXTRACT_FIRST extracts the first word from a string.
-
SORT_HEAP_EXTERNAL externally sorts a list of items into ascending order.
-
TIMESTAMP prints the current YMDHMS date as a time stamp.
You can go up one level to
the C source codes.
Last revised on 21 January 2014.