Drop the dependency on libunistring

This commit is contained in:
Kovid Goyal
2018-01-18 00:09:40 +05:30
parent 2ddc7e8c80
commit 5faa649452
11 changed files with 2375 additions and 39 deletions

View File

@@ -1,41 +1,22 @@
#pragma once
#include "data-types.h"
#include <unictype.h>
#include <uninorm.h>
static inline bool
is_combining_char(uint32_t ch) {
return uc_is_general_category_withtable(ch, UC_CATEGORY_MASK_M);
}
static inline bool
is_ignored_char(uint32_t ch) {
return uc_is_general_category_withtable(ch, UC_CATEGORY_MASK_Cc | UC_CATEGORY_MASK_Cf | UC_CATEGORY_MASK_Cs);
}
static inline bool
is_word_char(uint32_t ch) {
return uc_is_general_category_withtable(ch, UC_CATEGORY_MASK_L | UC_CATEGORY_MASK_N);
}
bool is_combining_char(char_type ch);
bool is_ignored_char(char_type ch);
bool is_word_char(char_type ch);
bool is_CZ_category(char_type);
bool is_P_category(char_type);
static inline bool
is_url_char(uint32_t ch) {
return ch && !uc_is_general_category_withtable(ch, UC_CATEGORY_MASK_C | UC_CATEGORY_MASK_Z);
}
static inline uint32_t
normalize(uint32_t ch, uint32_t cc1, uint32_t cc2) {
uint32_t ans = uc_composition(ch, cc1);
if (ans && cc2) ans = uc_composition(ans, cc2);
return ans;
return ch && !is_CZ_category(ch);
}
static inline bool
can_strip_from_end_of_url(uint32_t ch) {
// remove trailing punctuation
return (
(uc_is_general_category_withtable(ch, UC_CATEGORY_MASK_P) && ch != '/') ||
(is_P_category(ch) && ch != '/') ||
ch == '>'
) ? true : false;
}