ruby/yarp/util/yp_char.h
Aaron Patterson abce8583e2 [ruby/yarp] Fix heredocs inside %W and %w lists
The problem was that we were treating heredoc bodies as part of the %W
list because we didn't push the scanning cursor past the heredoc after
lexing out the here doc.  To fix this, we changed the whitespace
scanning function to quit scanning when it reaches a newline but only in
the case that a heredoc is present.

Additionally, we need to prevent double counting newlines in the case of
a heredoc.  For example:

```ruby
%W(<<foo 123)
foo
```

The newline after the `)` is counted as part of scanning the heredoc, so
we added logic to prevent double counting the newline when scanning the
rest of the %W list.

eb090d8126

Co-authored-by: Jemma Issroff <jemmaissroff@gmail.com>
2023-07-20 14:58:11 +00:00

75 lines
3.2 KiB
C

#ifndef YP_CHAR_H
#define YP_CHAR_H
#include "yarp/defines.h"
#include "yarp/util/yp_newline_list.h"
#include <stdbool.h>
#include <stddef.h>
// Returns the number of characters at the start of the string that are
// whitespace. Disallows searching past the given maximum number of characters.
size_t yp_strspn_whitespace(const char *string, ptrdiff_t length);
// Returns the number of characters at the start of the string that are
// whitespace while also tracking the location of each newline. Disallows
// searching past the given maximum number of characters.
size_t
yp_strspn_whitespace_newlines(const char *string, long length, yp_newline_list_t *newline_list, bool);
// Returns the number of characters at the start of the string that are inline
// whitespace. Disallows searching past the given maximum number of characters.
size_t yp_strspn_inline_whitespace(const char *string, ptrdiff_t length);
// Returns the number of characters at the start of the string that are decimal
// digits. Disallows searching past the given maximum number of characters.
size_t yp_strspn_decimal_digit(const char *string, ptrdiff_t length);
// Returns the number of characters at the start of the string that are
// hexadecimal digits. Disallows searching past the given maximum number of
// characters.
size_t yp_strspn_hexadecimal_digit(const char *string, ptrdiff_t length);
// Returns the number of characters at the start of the string that are octal
// digits or underscores. Disallows searching past the given maximum number of
// characters.
size_t yp_strspn_octal_number(const char *string, ptrdiff_t length);
// Returns the number of characters at the start of the string that are decimal
// digits or underscores. Disallows searching past the given maximum number of
// characters.
size_t yp_strspn_decimal_number(const char *string, ptrdiff_t length);
// Returns the number of characters at the start of the string that are
// hexadecimal digits or underscores. Disallows searching past the given maximum
// number of characters.
size_t yp_strspn_hexadecimal_number(const char *string, ptrdiff_t length);
// Returns the number of characters at the start of the string that are regexp
// options. Disallows searching past the given maximum number of characters.
size_t yp_strspn_regexp_option(const char *string, ptrdiff_t length);
// Returns the number of characters at the start of the string that are binary
// digits or underscores. Disallows searching past the given maximum number of
// characters.
size_t yp_strspn_binary_number(const char *string, ptrdiff_t length);
// Returns true if the given character is a whitespace character.
bool yp_char_is_whitespace(const char c);
// Returns true if the given character is an inline whitespace character.
bool yp_char_is_inline_whitespace(const char c);
// Returns true if the given character is a binary digit.
bool yp_char_is_binary_digit(const char c);
// Returns true if the given character is an octal digit.
bool yp_char_is_octal_digit(const char c);
// Returns true if the given character is a decimal digit.
bool yp_char_is_decimal_digit(const char c);
// Returns true if the given character is a hexadecimal digit.
bool yp_char_is_hexadecimal_digit(const char c);
#endif