Skip to content

Commit

Permalink
Documentation for pm_strncasecmp
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Nov 1, 2023
1 parent 88336e7 commit 2693426
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/prism.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions include/prism/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,4 @@
# define snprintf _snprintf
#endif

int pm_strncasecmp(const uint8_t *string1, const uint8_t *string2, size_t length);

#endif
27 changes: 27 additions & 0 deletions include/prism/util/pm_strncasecmp.h
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions prism.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 10 additions & 3 deletions src/util/pm_strncasecmp.c
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 2693426

Please sign in to comment.