strorder.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* Copyright (C) 1995, 1996, 1999, 2000, 2004, 2006, 2008 Free Software Foundation, Inc.
  2. *
  3. * This library is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU Lesser General Public
  5. * License as published by the Free Software Foundation; either
  6. * version 2.1 of the License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * Lesser General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Lesser General Public
  14. * License along with this library; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  16. */
  17. #ifdef HAVE_CONFIG_H
  18. # include <config.h>
  19. #endif
  20. #include "libguile/_scm.h"
  21. #include "libguile/chars.h"
  22. #include "libguile/strings.h"
  23. #include "libguile/symbols.h"
  24. #include "libguile/validate.h"
  25. #include "libguile/strorder.h"
  26. #include "libguile/srfi-13.h"
  27. SCM_C_INLINE_KEYWORD static SCM
  28. srfi13_cmp (SCM s1, SCM s2, SCM (*cmp) (SCM, SCM, SCM, SCM, SCM, SCM))
  29. {
  30. if (scm_is_true (cmp (s1, s2,
  31. SCM_UNDEFINED, SCM_UNDEFINED,
  32. SCM_UNDEFINED, SCM_UNDEFINED)))
  33. return SCM_BOOL_T;
  34. else
  35. return SCM_BOOL_F;
  36. }
  37. SCM_DEFINE1 (scm_string_equal_p, "string=?", scm_tc7_rpsubr,
  38. (SCM s1, SCM s2),
  39. "Lexicographic equality predicate; return @code{#t} if the two\n"
  40. "strings are the same length and contain the same characters in\n"
  41. "the same positions, otherwise return @code{#f}.\n"
  42. "\n"
  43. "The procedure @code{string-ci=?} treats upper and lower case\n"
  44. "letters as though they were the same character, but\n"
  45. "@code{string=?} treats upper and lower case as distinct\n"
  46. "characters.")
  47. #define FUNC_NAME s_scm_string_equal_p
  48. {
  49. return srfi13_cmp (s1, s2, scm_string_eq);
  50. }
  51. #undef FUNC_NAME
  52. SCM_DEFINE1 (scm_string_ci_equal_p, "string-ci=?", scm_tc7_rpsubr,
  53. (SCM s1, SCM s2),
  54. "Case-insensitive string equality predicate; return @code{#t} if\n"
  55. "the two strings are the same length and their component\n"
  56. "characters match (ignoring case) at each position; otherwise\n"
  57. "return @code{#f}.")
  58. #define FUNC_NAME s_scm_string_ci_equal_p
  59. {
  60. return srfi13_cmp (s1, s2, scm_string_ci_eq);
  61. }
  62. #undef FUNC_NAME
  63. SCM_DEFINE1 (scm_string_less_p, "string<?", scm_tc7_rpsubr,
  64. (SCM s1, SCM s2),
  65. "Lexicographic ordering predicate; return @code{#t} if @var{s1}\n"
  66. "is lexicographically less than @var{s2}.")
  67. #define FUNC_NAME s_scm_string_less_p
  68. {
  69. return srfi13_cmp (s1, s2, scm_string_lt);
  70. }
  71. #undef FUNC_NAME
  72. SCM_DEFINE1 (scm_string_leq_p, "string<=?", scm_tc7_rpsubr,
  73. (SCM s1, SCM s2),
  74. "Lexicographic ordering predicate; return @code{#t} if @var{s1}\n"
  75. "is lexicographically less than or equal to @var{s2}.")
  76. #define FUNC_NAME s_scm_string_leq_p
  77. {
  78. return srfi13_cmp (s1, s2, scm_string_le);
  79. }
  80. #undef FUNC_NAME
  81. SCM_DEFINE1 (scm_string_gr_p, "string>?", scm_tc7_rpsubr,
  82. (SCM s1, SCM s2),
  83. "Lexicographic ordering predicate; return @code{#t} if @var{s1}\n"
  84. "is lexicographically greater than @var{s2}.")
  85. #define FUNC_NAME s_scm_string_gr_p
  86. {
  87. return srfi13_cmp (s1, s2, scm_string_gt);
  88. }
  89. #undef FUNC_NAME
  90. SCM_DEFINE1 (scm_string_geq_p, "string>=?", scm_tc7_rpsubr,
  91. (SCM s1, SCM s2),
  92. "Lexicographic ordering predicate; return @code{#t} if @var{s1}\n"
  93. "is lexicographically greater than or equal to @var{s2}.")
  94. #define FUNC_NAME s_scm_string_geq_p
  95. {
  96. return srfi13_cmp (s1, s2, scm_string_ge);
  97. }
  98. #undef FUNC_NAME
  99. SCM_DEFINE1 (scm_string_ci_less_p, "string-ci<?", scm_tc7_rpsubr,
  100. (SCM s1, SCM s2),
  101. "Case insensitive lexicographic ordering predicate; return\n"
  102. "@code{#t} if @var{s1} is lexicographically less than @var{s2}\n"
  103. "regardless of case.")
  104. #define FUNC_NAME s_scm_string_ci_less_p
  105. {
  106. return srfi13_cmp (s1, s2, scm_string_ci_lt);
  107. }
  108. #undef FUNC_NAME
  109. SCM_DEFINE1 (scm_string_ci_leq_p, "string-ci<=?", scm_tc7_rpsubr,
  110. (SCM s1, SCM s2),
  111. "Case insensitive lexicographic ordering predicate; return\n"
  112. "@code{#t} if @var{s1} is lexicographically less than or equal\n"
  113. "to @var{s2} regardless of case.")
  114. #define FUNC_NAME s_scm_string_ci_leq_p
  115. {
  116. return srfi13_cmp (s1, s2, scm_string_ci_le);
  117. }
  118. #undef FUNC_NAME
  119. SCM_DEFINE1 (scm_string_ci_gr_p, "string-ci>?", scm_tc7_rpsubr,
  120. (SCM s1, SCM s2),
  121. "Case insensitive lexicographic ordering predicate; return\n"
  122. "@code{#t} if @var{s1} is lexicographically greater than\n"
  123. "@var{s2} regardless of case.")
  124. #define FUNC_NAME s_scm_string_ci_gr_p
  125. {
  126. return srfi13_cmp (s1, s2, scm_string_ci_gt);
  127. }
  128. #undef FUNC_NAME
  129. SCM_DEFINE1 (scm_string_ci_geq_p, "string-ci>=?", scm_tc7_rpsubr,
  130. (SCM s1, SCM s2),
  131. "Case insensitive lexicographic ordering predicate; return\n"
  132. "@code{#t} if @var{s1} is lexicographically greater than or\n"
  133. "equal to @var{s2} regardless of case.")
  134. #define FUNC_NAME s_scm_string_ci_geq_p
  135. {
  136. return srfi13_cmp (s1, s2, scm_string_ci_ge);
  137. }
  138. #undef FUNC_NAME
  139. void
  140. scm_init_strorder ()
  141. {
  142. #include "libguile/strorder.x"
  143. }
  144. /*
  145. Local Variables:
  146. c-file-style: "gnu"
  147. End:
  148. */