forked from xolatile/xhartae
More text, unfinished chapter 1...
This commit is contained in:
parent
e7dc385b56
commit
0eace4863a
@ -9,4 +9,60 @@ It is distributed in the hope that it will be useful or harmful, it really depen
|
||||
#ifndef CHAPTER_1_SOURCE
|
||||
#define CHAPTER_1_SOURCE
|
||||
|
||||
int character_is_uppercase (char character) {
|
||||
return ((int) ((character >= 'A') && (character <= 'Z')));
|
||||
}
|
||||
|
||||
int character_is_lowercase (char character) {
|
||||
return ((int) ((character >= 'a') && (character <= 'z')));
|
||||
}
|
||||
|
||||
int character_is_digit (char character) {
|
||||
return ((int) ((character >= '0') && (character <= '9')));
|
||||
}
|
||||
|
||||
int character_is_blank (char character) {
|
||||
return ((int) ((character == ' ') || (character == '\t') || (character == '\r') || (character == '\n')));
|
||||
}
|
||||
|
||||
int character_is_alpha (char character) {
|
||||
return ((character_is_uppercase (character) != 0) || (character_is_lowercase (character) != 0));
|
||||
}
|
||||
|
||||
int character_is_symbol (char character) {
|
||||
return (character_compare_array (character, "~!@#$%^&*()+{}|:\"<>?`-=[]\\;',./"));
|
||||
}
|
||||
|
||||
int character_is_visible (char character) {
|
||||
return ((int) ((character >= ' ') && (character <= '~')));
|
||||
}
|
||||
|
||||
int character_is_invisible (char character) {
|
||||
return (character_is_visible (character) == 0);
|
||||
}
|
||||
|
||||
int character_is_escape (char character) {
|
||||
return ((int) (character == '\033'));
|
||||
}
|
||||
|
||||
int character_is_underscore (char character) {
|
||||
return ((int) (character == '_'));
|
||||
}
|
||||
|
||||
int character_is_hexadecimal (char character) {
|
||||
return (character_compare_array (character, "0123456789ABCDEF"));
|
||||
}
|
||||
|
||||
int character_compare_array (char character, char * character_array) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i != string_length (character_array); ++i)
|
||||
if (character == character_array [i]) {
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -65,6 +65,28 @@ Okay, now we're left with following actually useful and C-loving keywords, 18 of
|
||||
- return: Used in functions to return from them with or without a result (return value). It's best when function only uses it once.
|
||||
- break: When inside a loop, this statement will exit the loop. In newer standards it can take simple arguments, but we'll see why that's bad.
|
||||
- continue: Even more specific case, when inside a loop, this statement will skip to the end of the loop, and then continue again.
|
||||
|
||||
Now, of those 18 actually useful C keywords, I like to avoid 'struct', 'switch', 'case', 'default', 'while', and use (functional) 'static' and 'extern' only in order to silence
|
||||
compiler warnings, 'static' inside a function is more useful. That leaves us (me) with 12 C keywords that I love, out of complete 32 keywords in ANSI C standard. However, we'll
|
||||
see that sometimes is preferable to use switch statement somewhere, or while loop when for loop feels like overkill. In most real-world cases, you'll need to use some API or
|
||||
library that internally used structures everywhere, so you'll need to adapt to it, we'll see examples later...
|
||||
|
||||
So, real men need these keywords { char, int, void, sizeof, static, if, else, for, enum, return }, and use the rest of them in order to silence compiler warnings, use some
|
||||
standard library functions, clean the source code or access an API / library / header file.
|
||||
*/
|
||||
|
||||
extern int character_is_uppercase (char character);
|
||||
extern int character_is_lowercase (char character);
|
||||
extern int character_is_digit (char character);
|
||||
extern int character_is_blank (char character);
|
||||
extern int character_is_alpha (char character);
|
||||
extern int character_is_symbol (char character);
|
||||
extern int character_is_visible (char character);
|
||||
extern int character_is_invisible (char character);
|
||||
extern int character_is_escape (char character);
|
||||
extern int character_is_underscore (char character);
|
||||
extern int character_is_hexadecimal (char character);
|
||||
|
||||
extern int character_compare_array (char character, char * character_array);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user