ASCII.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef ASCII_HEADER
  2. #define ASCII_HEADER
  3. // this header needs
  4. #include <stdio.h>
  5. #include "../ARRAY.h"
  6. // #include "UNICD.h" (see down below!)
  7. // typedefs
  8. typedef umax ascii_int; // ASCII integer representation
  9. // the integer representation is the same as the encoded representation
  10. // https://en.wikipedia.org/wiki/ASCII
  11. #define MIN_ASCII_INT 0x00
  12. #define MAX_ASCII_INT 0x7F
  13. #define INV_ASCII_INT 0xFF
  14. #define INV_ASCII_INT_STR "[INV_ASCII_INT]"
  15. #define INV_ENC_ASCII_STR "[INV_ENC_ASCII]"
  16. // ASCII character table
  17. #define ASCII_INT_CHAR_TB_LENGTH 0x80
  18. ascii_int ASCII_INT_CHAR_TB[ASCII_INT_CHAR_TB_LENGTH] = {
  19. /* 0x00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, '\a', '\b', '\t', '\n', '\v', '\f', '\r', 0x0E, 0x0F,
  20. /* 0x10 */ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
  21. /* 0x20 */ ' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
  22. /* 0x30 */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
  23. /* 0x40 */ '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  24. /* 0x50 */ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
  25. /* 0x60 */ '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
  26. /* 0x70 */ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', 0x7F
  27. };
  28. // table definitions
  29. #define ASCII_INT_CTRL_CHARS_START 0x00
  30. #define ASCII_INT_CTRL_CHARS_END 0x19
  31. #define ASCII_INT_PRINT_CHARS_START 0x20
  32. #define ASCII_INT_PRINT_CHARS_END 0x7F
  33. #define ASCII_INT_COMMA 0x2C
  34. #define ASCII_INT_NEWLN 0xA0
  35. #define ASCII_INT_WHITESPACE_LENGTH 6
  36. ascii_int ASCII_INT_WHITESPACE[ASCII_INT_WHITESPACE_LENGTH] =
  37. {
  38. '\t', // 0x09 (horizontal tab)
  39. '\n', // 0x0A (line feed)
  40. '\v', // 0x0B (vertical tab)
  41. '\f', // 0x0C (form feed)
  42. '\r', // 0x0D (carriage return)
  43. ' ' // 0x20 (space)
  44. };
  45. #define ASCII_INT_NUMBER_BEGIN 0
  46. #define ASCII_INT_NUMBER_HEX_UPPER_BEGIN 10
  47. #define ASCII_INT_NUMBER_HEX_LOWER_BEGIN 16
  48. #define ASCII_INT_NUMBER_PMDX_BEGIN 22
  49. #define ASCII_INT_NUMBER_LENGTH 26
  50. ascii_int ASCII_INT_NUMBER[ASCII_INT_NUMBER_LENGTH] =
  51. {
  52. /* 0x30 */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', // octal/decimal
  53. /* 0x41 */ 'A', 'B', 'C', 'D', 'E', 'F', // hex uppercase
  54. /* 0x61 */ 'a', 'b', 'c', 'd', 'e', 'f', // hex lowercase
  55. // other usual chars
  56. /* 0x2B */ '+',
  57. /* 0x2D */ '-',
  58. /* 0x2E */ '.',
  59. /* 0x78 */ 'x'
  60. };
  61. // checking
  62. byte check_ascii_int(ascii_int ch);
  63. byte check_enc_ascii(void * src, umax ssize);
  64. // get/write (the best duo)
  65. ascii_int get_ascii_int(void * src, umax ssize);
  66. void * write_enc_ascii(ascii_int ch, void * dest, umax dsize);
  67. // printing
  68. byte print_ascii_int(ascii_int ch);
  69. byte print_enc_ascii(void * src, umax ssize);
  70. // unicode conversion related (for compatibility with CHAR_ARR functions)
  71. // important header position!!!
  72. #include "UNICD.h"
  73. // checking
  74. byte check_ascii_as_unicd(ascii_int ch);
  75. bool check_unicd_as_ascii(unicd_int ch);
  76. // getting
  77. unicd_int get_ascii_as_unicd(ascii_int ch);
  78. ascii_int get_unicd_as_ascii(unicd_int ch);
  79. #include "ASCII.c"
  80. #endif // ASCII_HEADER