CharactersAndCharSets - Characters and Character Sets...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Characters and Character Sets Beta Draft - Do not distribute © 2001, By Randall Hyde Page 439 Character s and Character Sets Chapter Three 3.1 Chapter Overview This chapter completes the discussion of the character data type by describing se v eral character transla - tion and classifi cation functions found in the HLA Standard Library . These functions pro vide most of the character operations that aren’ t tri vial to realize using a fe w 80x86 machine instructions. This chapter also introduces another composite data type based on the character – the character set data type. Character sets and their associated operations, let you quickly test characters to see if the y belong to some set. These operations also let you manipulate sets of characters using f amiliar operations lik e set union, intersection, and dif ference. 3.2 The HLA Standard Library CHARS.HHF Module The HLA Standard Library chars.hhf module pro vides a couple of routines that con v ert characters from one form to another and se v eral routines that classify characters according to their graphic representation. These functions are especially useful for processing user input to v erify that it is correct. The fi rst tw o routines we will consider are the translation/con v ersion functions. These functions are c har s.toUpper and c har s.toLower . These functions use the follo wing syntax: chars.toLower( characterValue ); // Returns converted character in AL. chars.toUpper( characterValue ); // Returns converted character in AL. These tw o functions require a byte-sized parameter (typically a register or a char variable). They check the character to see if it is an alphabetic character; if it is not, then these functions return the unmodified param- eter value in the AL register. If the character is an alphabetic character, then these functions may translate the value depending on the particular function. The chars.toUpper function translates lower case alphabetic characters to upper case; it returns upper case character unmodified. The chars.toLower function does the converse – it translates upper case characters to lower case characters and leaves lower case characters alone. These two functions are especially useful when processing user input containing alphabetic characters. For example, suppose you expect a “Y” or “N” answer from the user at some point in your program. You code might look like the following: forever stdout.put( “Answer ‘Y’ or ‘N’:” ); stdin.FlushInput(); // Force input of new line of text. stdin.getc(); // Read user input in AL. breakif( al = ‘Y’ ); breakif( al = ‘N’ ); stdout.put( “Illegal input, please reenter”, nl ); endfor; The problem with this program is that the user must answer e xactly “Y” or “N” (using upper case) or the program will reject the user’s input. This means that the program will reject “y” and “n” since the ASCII codes for these characters are different than “Y” and “N”.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 24

CharactersAndCharSets - Characters and Character Sets...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online