История изменений
Исправление shdown, (текущая версия) :
Ну ЛОЛ же ну.
Ну и чего мне твой анализ рубежей? Не, ты покажи, как ты собираешься с libicu посчитать эту хрень для терминоля.
Хорошо, установил я твой konsole. Он сдвигает курсор на два знакоместа. Как мне это посчитать с помощью libicu?
#include <unicode/ubrk.h>
#include <unicode/utypes.h>
#include <unicode/ustring.h>
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
int count_grapheme_clusters(const UChar *text, int32_t length) {
UErrorCode status = U_ZERO_ERROR;
int count = 0;
// Create a character break iterator (grapheme cluster boundaries)
UBreakIterator *bi = ubrk_open(UBRK_CHARACTER, "en_US", text, length, &status);
if (U_FAILURE(status)) {
fprintf(stderr, "Error opening break iterator: %s\n", u_errorName(status));
return -1;
}
int32_t boundary = ubrk_first(bi);
while (boundary != UBRK_DONE) {
int32_t next = ubrk_next(bi);
if (next == UBRK_DONE) break;
count++;
boundary = next;
}
ubrk_close(bi);
return count;
}
int main() {
enum { N = 2048 };
UChar text[N];
UErrorCode status = U_ZERO_ERROR;
size_t nline = 0;
char *line = NULL;
if (getline(&line, &nline, stdin) <= 0) {
fprintf(stderr, "getline() failed.\n");
return 1;
}
if (strlen(line) && line[strlen(line) - 1] == '\n') {
line[strlen(line) - 1] = '\0';
}
int32_t destLength;
u_strFromUTF8(text, N, &destLength, line, -1, &status);
if (U_FAILURE(status)) {
fprintf(stderr, "Conversion error: %s\n", u_errorName(status));
return 1;
}
int graphemes = count_grapheme_clusters(text, destLength);
printf("Grapheme clusters: %d\n", graphemes);
printf("UTF-16 code units: %d\n", destLength);
return 0;
}
Она говорит, что 1 grapheme cluster.
Исходная версия shdown, :
Ну ЛОЛ же ну.
Ну и чего мне твой анализ рубежей? Не, ты покажи, как ты собираешься с libicu посчитать эту хрень для терминоля.
Хорошо, установил я твой konsole. Он сдвигает курсор на два символа. Как мне это посчитать с помощью libicu?
#include <unicode/ubrk.h>
#include <unicode/utypes.h>
#include <unicode/ustring.h>
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
int count_grapheme_clusters(const UChar *text, int32_t length) {
UErrorCode status = U_ZERO_ERROR;
int count = 0;
// Create a character break iterator (grapheme cluster boundaries)
UBreakIterator *bi = ubrk_open(UBRK_CHARACTER, "en_US", text, length, &status);
if (U_FAILURE(status)) {
fprintf(stderr, "Error opening break iterator: %s\n", u_errorName(status));
return -1;
}
int32_t boundary = ubrk_first(bi);
while (boundary != UBRK_DONE) {
int32_t next = ubrk_next(bi);
if (next == UBRK_DONE) break;
count++;
boundary = next;
}
ubrk_close(bi);
return count;
}
int main() {
enum { N = 2048 };
UChar text[N];
UErrorCode status = U_ZERO_ERROR;
size_t nline = 0;
char *line = NULL;
if (getline(&line, &nline, stdin) <= 0) {
fprintf(stderr, "getline() failed.\n");
return 1;
}
if (strlen(line) && line[strlen(line) - 1] == '\n') {
line[strlen(line) - 1] = '\0';
}
int32_t destLength;
u_strFromUTF8(text, N, &destLength, line, -1, &status);
if (U_FAILURE(status)) {
fprintf(stderr, "Conversion error: %s\n", u_errorName(status));
return 1;
}
int graphemes = count_grapheme_clusters(text, destLength);
printf("Grapheme clusters: %d\n", graphemes);
printf("UTF-16 code units: %d\n", destLength);
return 0;
}
Она говорит, что 1 grapheme cluster.