poe

Уређивач .po фајлова
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 54025aa597d5162628e7e1604c609472d12d6828
родитељ af91c2fc747f16c01a05dc26c354803b3f994230
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Wed,  9 Feb 2022 23:10:29 +0100

WIP fix newlines, continued

Signed-off-by: Страхиња Радић <contact@strahinja.org>

Diffstat:
Mpo.c | 2--
Mpoe.c | 2++
Mutil.c | 81++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Mutil.h | 2++
измењених датотека: 4, додавања: 82(+), брисања: 5(-)

diff --git a/po.c b/po.c @@ -714,12 +714,10 @@ save_loop_entries_start: if (len == 0) continue; - /* TODO: Fixme */ u8_msgstr = calloc(len + 1, UTF8REPMAX); if (!u8_msgstr) return SAVE_ERR_CANT_ALLOC; - /* TODO: Fixme */ unicode_string_to_u8(u8_msgstr, old_pumsgstr, len); if (first_entry diff --git a/poe.c b/poe.c @@ -510,6 +510,8 @@ save_msgstr(struct DrawState* state) state->info_rows_count = 0; state->info_buffer = NULL; u32_encode_tabs(to_save, to_save_size * sizeof(uint32_t)); + u32_match_msgid_ending(state->entries[state->msgid_number - 1].msgid, + to_save, to_save_size * sizeof(uint32_t)); u32_set_msgstr(&state->entries[state->msgid_number - 1], to_save, state->msgstr_index, 0, state); state->input_changed_fuzzy = UNCHANGED; diff --git a/util.c b/util.c @@ -60,9 +60,70 @@ unicode_string_to_u8(char* s, const uint32_t* us, const size_t max) size_t u32_match_msgid_ending(const uint32_t* msgid, uint32_t* msgstr, size_t max) { - size_t newlen = 0; - /*TODO: WIP*/ - return newlen; + uint32_t* buf = calloc(max + 1, sizeof(uint32_t)); + if (!buf) + return 0; + size_t buf_len = 0; + size_t msgid_len = 0; + + buf_len = u32_strcpy(buf, msgstr); + msgid_len = u32_strlen(msgid); + + if (msgid_len > 1 + && u32_starts_with(msgid + msgid_len - 2, (uint32_t*)L"\\n")) + { + if (!(buf_len > 1 + && u32_starts_with(buf + buf_len - 2, + (uint32_t*)L"\\n"))) + { + buf_len += 2; + buf[buf_len - 2] = '\\'; + buf[buf_len - 1] = 'n'; + buf[buf_len] = 0; + } + } + else if (msgid_len > 0 + && u32_strstr((uint32_t*)L" .", msgid + msgid_len - 1)) + { + if (!(buf_len > 0 + && u32_strstr((uint32_t*)L" .", buf + buf_len - 1))) + { + buf_len++; + buf[buf_len - 1] = msgid[msgid_len - 1]; + buf[buf_len] = 0; + } + } + else if (buf_len > 1 + && u32_starts_with(buf + buf_len - 2, + (uint32_t*)L"\\n")) + { + buf_len -= 2; + buf[buf_len] = 0; + } + else if (buf_len > 0 + && u32_strstr((uint32_t*)L" .", buf + buf_len - 1)) + { + buf_len--; + buf[buf_len] = 0; + } + + u32_strncpy(msgstr, buf, max); + + return buf_len; +} + +size_t +u32_num_chars(uint32_t* s, uint32_t ch) +{ + size_t result = 0; + uint32_t* ps = s; + while (*ps) + { + if (*ps == ch) + result++; + ps++; + } + return result; } size_t @@ -165,6 +226,20 @@ u32_strchr(uint32_t* haystack, const uint32_t needle) } size_t +u32_strcpy(uint32_t* to, const uint32_t* from) +{ + const uint32_t* pfrom = from; + size_t copied = 0; + while (*pfrom) + { + *to++ = *pfrom++; + copied++; + } + *to = 0; + return copied; +} + +size_t u32_strncpy(uint32_t* to, const uint32_t* from, size_t max) { const uint32_t* pfrom = from; diff --git a/util.h b/util.h @@ -31,11 +31,13 @@ size_t u8_string_to_unicode(uint32_t* us, const char* s, const size_t max); size_t unicode_string_to_u8(char* s, const uint32_t* us, const size_t max); size_t u32_match_msgid_ending(const uint32_t* msgid, uint32_t* msgstr, size_t max); +size_t u32_num_chars(uint32_t* s, uint32_t ch); size_t u32_encode_tabs(uint32_t* s, size_t max); size_t u32_decode_tabs(uint32_t* s, size_t max); size_t u32_strlen(const uint32_t* s); uint32_t* u32_strstr(uint32_t* haystack, const uint32_t* needle); uint32_t* u32_strchr(uint32_t* haystack, const uint32_t needle); +size_t u32_strcpy(uint32_t* to, const uint32_t* from); size_t u32_strncpy(uint32_t* to, const uint32_t* from, size_t max); size_t u32_strncat(uint32_t* to, const uint32_t* from, size_t max); size_t u32_u8_strncpy(uint32_t* to, const char* from, size_t max);