diff options
| author | Kevin Newton <kddnewton@gmail.com> | 2023-10-30 23:33:04 -0400 |
|---|---|---|
| committer | Kevin Newton <kddnewton@gmail.com> | 2023-11-01 13:10:29 -0400 |
| commit | 493439c9ce8d298f3fbd2c9c01d35fcc9add6d49 (patch) | |
| tree | 1315390f159ec7bff4fe5d59e6f7bc01fc19208e | |
| parent | e8a72b516f141de9581c2edd1d8eb101739477bb (diff) | |
[ruby/prism] Documentation for pm_strncasecmp
https://github.com/ruby/prism/commit/26934263b7
| -rw-r--r-- | lib/prism/prism.gemspec | 1 | ||||
| -rw-r--r-- | prism/defines.h | 2 | ||||
| -rw-r--r-- | prism/prism.h | 1 | ||||
| -rw-r--r-- | prism/util/pm_strncasecmp.c | 13 | ||||
| -rw-r--r-- | prism/util/pm_strncasecmp.h | 27 |
5 files changed, 39 insertions, 5 deletions
diff --git a/lib/prism/prism.gemspec b/lib/prism/prism.gemspec index f93035aa18..5662fd4284 100644 --- a/lib/prism/prism.gemspec +++ b/lib/prism/prism.gemspec @@ -57,6 +57,7 @@ Gem::Specification.new do |spec| "include/prism/util/pm_memchr.h", "include/prism/util/pm_newline_list.h", "include/prism/util/pm_state_stack.h", + "include/prism/util/pm_strncasecmp.h", "include/prism/util/pm_string.h", "include/prism/util/pm_string_list.h", "include/prism/util/pm_strpbrk.h", diff --git a/prism/defines.h b/prism/defines.h index 531462a560..f697b9e554 100644 --- a/prism/defines.h +++ b/prism/defines.h @@ -49,6 +49,4 @@ # define snprintf _snprintf #endif -int pm_strncasecmp(const uint8_t *string1, const uint8_t *string2, size_t length); - #endif diff --git a/prism/prism.h b/prism/prism.h index 9dcecbb976..46bfae0fe0 100644 --- a/prism/prism.h +++ b/prism/prism.h @@ -5,6 +5,7 @@ #include "prism/util/pm_buffer.h" #include "prism/util/pm_char.h" #include "prism/util/pm_memchr.h" +#include "prism/util/pm_strncasecmp.h" #include "prism/util/pm_strpbrk.h" #include "prism/ast.h" #include "prism/diagnostic.h" diff --git a/prism/util/pm_strncasecmp.c b/prism/util/pm_strncasecmp.c index fce11835e0..2240bf8110 100644 --- a/prism/util/pm_strncasecmp.c +++ b/prism/util/pm_strncasecmp.c @@ -1,7 +1,14 @@ -#include <ctype.h> -#include <stddef.h> -#include <stdint.h> +#include "prism/util/pm_strncasecmp.h" +/** + * Compare two strings, ignoring case, up to the given length. Returns 0 if the + * strings are equal, a negative number if string1 is less than string2, or a + * positive number if string1 is greater than string2. + * + * Note that this is effectively our own implementation of strncasecmp, but it's + * not available on all of the platforms we want to support so we're rolling it + * here. + */ int pm_strncasecmp(const uint8_t *string1, const uint8_t *string2, size_t length) { size_t offset = 0; diff --git a/prism/util/pm_strncasecmp.h b/prism/util/pm_strncasecmp.h new file mode 100644 index 0000000000..6cf7aa8023 --- /dev/null +++ b/prism/util/pm_strncasecmp.h @@ -0,0 +1,27 @@ +#ifndef PRISM_STRNCASECMP_H +#define PRISM_STRNCASECMP_H + +#include "prism/defines.h" + +#include <ctype.h> +#include <stddef.h> +#include <stdint.h> + +/** + * Compare two strings, ignoring case, up to the given length. Returns 0 if the + * strings are equal, a negative number if string1 is less than string2, or a + * positive number if string1 is greater than string2. + * + * Note that this is effectively our own implementation of strncasecmp, but it's + * not available on all of the platforms we want to support so we're rolling it + * here. + * + * @param string1 The first string to compare. + * @param string2 The second string to compare + * @param length The maximum number of characters to compare. + * @return 0 if the strings are equal, a negative number if string1 is less than + * string2, or a positive number if string1 is greater than string2. + */ +int pm_strncasecmp(const uint8_t *string1, const uint8_t *string2, size_t length); + +#endif |
