~begs/hru

d11d3169d8741811cef44d2375d673024cc42270 — Maxim Karasev 11 months ago 6d95718
grunt.c: get rid of utf8proc_isupper()

Slightly improves performance.
1 files changed, 26 insertions(+), 13 deletions(-)

M grunt.c
M grunt.c => grunt.c +26 -13
@@ 5,9 5,18 @@
#include <unistd.h>

/* Returns true if given codepoint belongs to cyrillic characters range
 * [а-яА-ЯёЁ], otherwise false. */
bool cyr_isalpha(int c) {
	if ((c >= 1040 && c <= 1103) || c == 1105 || c == 1025) {
 * [а-яё], otherwise false. */
bool cyr_islower(int c) {
	if ((c >= 1072 && c <= 1103) || c == 1105) {
		return 1;
	}
	return 0;
}

/* Returns true if given codepoint belongs to cyrillic characters range
 * [А-ЯЁ], otherwise false. */
bool cyr_isupper(int c) {
	if ((c >= 1040 && c <= 1071) || c == 1025) {
		return 1;
	}
	return 0;


@@ 20,23 29,26 @@ int convert_char(struct grunt_options options, utf8proc_int32_t *chptr,
	// Initlaize helper variable to avoid multiple dereferencing
	utf8proc_int32_t ch = *chptr;
	const char *s;
	bool uppercase;

	// Determine correct substitution string if any
	if (isalpha(ch)) {
	// Determine correct substitution string and case
	if (islower(ch)) {
		s = options.grunt;
		uppercase = false;
	} else if (isupper(ch)) {
		s = options.grunt;
	} else if (cyr_isalpha(ch)) {
		uppercase = true;
	} else if (cyr_islower(ch)) {
		s = options.cyr_grunt;
		uppercase = false;
	} else if (cyr_isupper(ch)) {
		s = options.cyr_grunt;
		uppercase = true;
	} else {
		*chptr = ch;
		return 0;
	}

	// Record case of character
	bool uppercase = false;
	if (utf8proc_isupper(ch)) {
		uppercase = true;
	}

	// Loop on the last codepoint
	int len = strlen(s);
	if (grunt_pos >= len) {


@@ 80,7 92,8 @@ bool convert_text(struct grunt_options options, char *string, int len) {
		}

		// Overwrite original character with substitution
		utf8proc_encode_char(ch, (unsigned char *)string_pos - char_size);
		utf8proc_encode_char(ch,
			(unsigned char *)string_pos - char_size);
	}

	return 1;