Skip to content

Commit 2693426

Browse files
committed
Documentation for pm_strncasecmp
1 parent 88336e7 commit 2693426

File tree

5 files changed

+39
-5
lines changed

5 files changed

+39
-5
lines changed

include/prism.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "prism/util/pm_buffer.h"
66
#include "prism/util/pm_char.h"
77
#include "prism/util/pm_memchr.h"
8+
#include "prism/util/pm_strncasecmp.h"
89
#include "prism/util/pm_strpbrk.h"
910
#include "prism/ast.h"
1011
#include "prism/diagnostic.h"

include/prism/defines.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,4 @@
4949
# define snprintf _snprintf
5050
#endif
5151

52-
int pm_strncasecmp(const uint8_t *string1, const uint8_t *string2, size_t length);
53-
5452
#endif
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef PRISM_STRNCASECMP_H
2+
#define PRISM_STRNCASECMP_H
3+
4+
#include "prism/defines.h"
5+
6+
#include <ctype.h>
7+
#include <stddef.h>
8+
#include <stdint.h>
9+
10+
/**
11+
* Compare two strings, ignoring case, up to the given length. Returns 0 if the
12+
* strings are equal, a negative number if string1 is less than string2, or a
13+
* positive number if string1 is greater than string2.
14+
*
15+
* Note that this is effectively our own implementation of strncasecmp, but it's
16+
* not available on all of the platforms we want to support so we're rolling it
17+
* here.
18+
*
19+
* @param string1 The first string to compare.
20+
* @param string2 The second string to compare
21+
* @param length The maximum number of characters to compare.
22+
* @return 0 if the strings are equal, a negative number if string1 is less than
23+
* string2, or a positive number if string1 is greater than string2.
24+
*/
25+
int pm_strncasecmp(const uint8_t *string1, const uint8_t *string2, size_t length);
26+
27+
#endif

prism.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Gem::Specification.new do |spec|
5757
"include/prism/util/pm_memchr.h",
5858
"include/prism/util/pm_newline_list.h",
5959
"include/prism/util/pm_state_stack.h",
60+
"include/prism/util/pm_strncasecmp.h",
6061
"include/prism/util/pm_string.h",
6162
"include/prism/util/pm_string_list.h",
6263
"include/prism/util/pm_strpbrk.h",

src/util/pm_strncasecmp.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
#include <ctype.h>
2-
#include <stddef.h>
3-
#include <stdint.h>
1+
#include "prism/util/pm_strncasecmp.h"
42

3+
/**
4+
* Compare two strings, ignoring case, up to the given length. Returns 0 if the
5+
* strings are equal, a negative number if string1 is less than string2, or a
6+
* positive number if string1 is greater than string2.
7+
*
8+
* Note that this is effectively our own implementation of strncasecmp, but it's
9+
* not available on all of the platforms we want to support so we're rolling it
10+
* here.
11+
*/
512
int
613
pm_strncasecmp(const uint8_t *string1, const uint8_t *string2, size_t length) {
714
size_t offset = 0;

0 commit comments

Comments
 (0)