You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.3KB

  1. #ifndef __STRING_H__
  2. #define __STRING_H__
  3. #ifdef __cplusplus
  4. #include <iostream>
  5. #include <string.h>
  6. #include <string>
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. /*
  10. * Cette classe permet de stocker des chaînes de caractères simplement.
  11. * Elle est une base essentielle et permet d'effectuer énormément d'opérations:
  12. * - set fonctionne comme sprintf, et réassigne la chaîne.
  13. * - to_charp() transforme la chaîne en pointeur.
  14. * - to_charp(from) extrait la chaîne depuis le caractère numéro from
  15. * - to_charp(from, to) extrait la chaîne depuis le caractère numéro from
  16. * jusqu'au caractère numéro to.
  17. * ATTENTION: les fonctions to_charp renvoie un pointeur sur un tableau
  18. * statique, et ce tableau sera modifié au prochain
  19. * appel à to_charp ou a set.
  20. * - to_int transforme la chaîne en int.
  21. * - to_double transforme la chaîne en double
  22. * - to_sqldate effectue la conversion suivante: DD/MM/YYYY ==> YYYYMMDD
  23. * - to_sqltime effectue la conversion suivante: h:m ==> h * 60 + m
  24. * - from_sqldate et from_sqltime effectue les conversions inverses.
  25. * - is_date, is_number, is_float, is_time renvoient des booléens de test.
  26. * - strlen renvoie la longueur de la chaine
  27. * - strchr(c) renvoie la position du caractère c
  28. * - strchr(c, p) recherche le caractère c à partir de la position p
  29. * - strrchr(c) renvoie la position du caractère c, en recherchant depuis la droite.
  30. * - strstr(s) renvoie la position de la chaine s
  31. * NOTE: les fonctions de recherche renvoient un résultat négatif si pas trouvé.
  32. * - strchrcnt(c) compte le nombre d'occurences du caractère c.
  33. *
  34. * Les opérateurs !=, ==, <=, >=, < et > permettent de comparer deux chaînes, en mode
  35. * 'case sensitive'. L'operateur [] renvoie un caractère de la chaîne.
  36. *
  37. * Les opérateurs << et >> vers un ostream ou depuis un istream sont supportés.
  38. */
  39. /*
  40. class String {
  41. public:
  42. String(const String &);
  43. String(const char * = NULL);
  44. String(char);
  45. String(int);
  46. String(double);
  47. ~String();
  48. char * set(char *, ...);
  49. char * to_charp(size_t = 0, ssize_t = -1) const;
  50. int to_int() const;
  51. string to_string() const;
  52. double to_double() const;
  53. String to_sqldate() const;
  54. String to_sqltime() const;
  55. String from_sqldate() const;
  56. String from_sqltime() const;
  57. bool is_date() const;
  58. bool is_number() const;
  59. bool is_float() const;
  60. bool is_time() const;
  61. size_t strlen() const;
  62. ssize_t strchr(char, size_t = 0) const;
  63. ssize_t strrchr(char) const;
  64. ssize_t strstr(const String &) const;
  65. int strchrcnt(char) const;
  66. String & operator=(const String &);
  67. String operator+(const String &) const;
  68. String & operator+=(const String &);
  69. bool operator!=(const String &) const;
  70. bool operator==(const String &) const;
  71. bool operator<=(const String &) const;
  72. bool operator>=(const String &) const;
  73. bool operator<(const String &) const;
  74. bool operator>(const String &) const;
  75. char operator[](size_t i) const;
  76. private:
  77. static char t[BUFSIZ];
  78. char * str;
  79. };
  80. ostream & operator<<(ostream &, const String &);
  81. istream & operator>>(istream &, String &);
  82. */
  83. #else
  84. #error This only works with a C++ compiler
  85. #endif
  86. #endif