I have a problem with my code. I see these errors in the following lines of code.
for (int i = 0; i < strlen(string); i++) {
encrypt_string[current_element] = string[i];
current_element++;
if (string[i] == 'а' || string[i] == 'е' ||
string[i] == 'и' || string[i] == 'о' ||
string[i] == 'у' || string[i] == 'я' || string[i] == 'Я' ||
string[i] == 'ы' || string[i] == 'ё' ||
string[i] == 'ю' || string[i] == 'я' ||
string[i] == 'э' || string[i] == 'a' ||
string[i] == 'e' || string[i] == 'i' ||
string[i] == 'o' || string[i] == 'u' ||
string[i] == 'y') {
encrypt_string[current_element] = 'л';
encrypt_string[current_element+1] = 'а';
current_element += 2;
}
}
I tried to google on this topic, but the advice on the Internet does not help (Char_16T, Char_32T, ETC.). Perhaps this does not work with MacOS or Clang ++ compiler.
How I can do it on Mac?
0 / 0 / 0 Регистрация: 28.03.2015 Сообщений: 13 |
|
1 |
|
28.03.2015, 22:33. Показов 17016. Ответов 6
Здравствуйте, недавно перешел в среду Xcode (перешел с VisualStudio) и столкнулся с такой проблемой: Миниатюры
__________________
0 |
korvin_ 4016 / 2618 / 475 Регистрация: 28.04.2012 Сообщений: 8,422 |
||||
28.03.2015, 23:45 |
2 |
|||
Решение
Здравствуйте, недавно перешел в среду Xcode (перешел с VisualStudio) и столкнулся с такой проблемой: Казалось бы, при чём тут линукс?
по непонятной мне причине я не могу присвоить переменной типа char русский символ. Например, для char c = ‘ы’; выдаёт ошибку «character too large for enclosing character literal type», хотя с латинскими символами все работает как надо. Дык русские символы в UTF-8 занимают 2 байта, а char вмещает только 1 байт.
Помогите справится с проблемой или дайте её решение. http://stackoverflow.com/quest… 8-encoding Добавлено через 21 минуту
1 |
550 / 383 / 125 Регистрация: 02.10.2008 Сообщений: 1,553 Записей в блоге: 1 |
|
28.03.2015, 23:47 |
3 |
У вас в коде setlocale(LC_ALL,»rus»); а разве не setlocale(LC_ALL,»ru_RU»)?
0 |
4016 / 2618 / 475 Регистрация: 28.04.2012 Сообщений: 8,422 |
|
28.03.2015, 23:55 |
4 |
2. А если пользователь вашей проги будет использовать не UTF-8, а KOI-8? Это будет довольно необычно. В OSX используется только UTF-8, насколько я знаю. Если только ТС не пишет текстовый редактор, который должен уметь работать с разными кодировками, что вряд ли.
0 |
550 / 383 / 125 Регистрация: 02.10.2008 Сообщений: 1,553 Записей в блоге: 1 |
|
29.03.2015, 00:13 |
5 |
Это будет довольно необычно. многие консольные bsd висят по прежнему на KOI. Писать не англоязычное и кроссплатформенное — то ещё веселье…
0 |
korvin_ |
29.03.2015, 00:30
|
Не по теме:
многие консольные bsd Что-то мне подсказывает, что ТС с ними никогда не столкнётся.
0 |
0 / 0 / 0 Регистрация: 28.03.2015 Сообщений: 13 |
|
29.03.2015, 01:06 [ТС] |
7 |
я пишу программку которая переводит текстовый файл в какой-либо кодировке на русский язык.Спасибо вам за помощь. Добавлено через 18 минут
0 |
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Closed
patrickt opened this issue
Jan 7, 2020
· 4 comments
Comments
Running tree-sitter test
produces the following error when compiling scanner.cc
:
emcc command failed - src/scanner.cc:88:32: error: character too large for enclosing character literal type
lexer->lookahead == 'uFEFF' ||
^
src/scanner.cc:89:32: error: character too large for enclosing character literal type
lexer->lookahead == 'u2060' ||
^
src/scanner.cc:90:32: error: character too large for enclosing character literal type
lexer->lookahead == 'u200B';
I’ve encountered this myself — if I remember correctly:
- You can comment out the affected lines for the time being if you just want to work on stuff (that’s what I did so far), these are more exotic whitespace cases which of course matter, but are irrelevant for the overall implementation and general testing.
- It only occurrs in certain compilation scenarios (when building for the wasm target?)
- I don’t have a solution yet!
- If you find one I’d be much obliged
In any case, thanks for the report! Glad about your interest in this, let me know if you have more questions and/or issues!
I fixed it by removing the character syntax:
inline bool is_horizontal_whitespace(TSLexer *lexer) { return lexer->lookahead == ' ' || lexer->lookahead == 't' || lexer->lookahead == 0xFEFF || lexer->lookahead == 0x2060 || lexer->lookahead == 0x200B; }
Yeah, I don’t think 'uFEFF'
is a valid C/C++ expression. Single quoted character literals are of type char
, which is almost always an 8-bit value. The largest numerical char
value is 0xFF
.
In more recent versions of C++, you can use a U
prefix (e.g. U'uFEFF'
). I think the normal way to write numbers like this is to just use integer syntax, like @patrickt said ☝️ .
Very cool, thanks patrick for the fix and max for the additional insight, appreciate it!
Commited in c059967
Locales
Hello all,
Recently, I have been trying to write a small program to practice C++. Since I’m from a French speaking region, I would like my program to be able to adjust to different locales.
To test my understanding of locale basics, I have written this code to test whether a char «a» is a letter or not (in the locale):
|
|
The program compiles fine, but returns «0» (thus, «è» is not a letter for the program).
What am I doing wrong here? It seems like the program is ignoring the locale.
FYI, I am programming on Ubuntu using GCC. The fr_CA.UTF-8 locale is installed on my computer but is not my default locale, which is en_CA.UTF-8.
Thank you!
Last edited on
What encoding do you use? I believe you need a single-byte encoding for both your file and locale to work properly.
MiiNiPaa,
Thanks for your reply. My .cpp file is encoded in UTF-8, which is not single-byte, according to this source: https://en.wikipedia.org/wiki/SBCS.
When I try using the two single-byte encodings in Eclipse, the letter ‘è’ is transformed as a weird sign for missing characters.
I’m not exactly sure I understand what you mean…
Try to use wide characters:
|
|
coder777,
Thanks for the comment. From what your telling me, it seems like I am not using the right tool to reach my goal… Would you have any suggestion as to what I could use to achieve this?
I could I test for French, Russian or Japanese characters (depending on the user’s locale)?
@MiiNiPaa: thanks for your suggestion, but sadly using wide chars is not working…
Last edited on
coder777,
Ok. The links you provided are really interesting, I will definitely look into that. I thought there was a straightforward way to do this…
I will keep your last suggestion in mind.
You don’t need boost to do what you’re trying to do, linux actually supports Unicode in C++ as the language intended (Windows is the outlier here)
The problem with the first program is that the character literal (something enclosed by single quotes) must be a single byte, and è
is not a single byte in UTF-8, which is what linux saves your source code file in. assuming normal configuration.
In fact, clang gives an error here:
|
|
and gcc gives a somewhat worse-worded warning:
|
|
MiiNiPaa is correct, you have to use a wide character or, alternatively, a string
Also, don’t use that hideous use_facet
The following works for me:
using wchar_t:
|
|
using UTF-8 strings:
|
|
By the way, you’re not using anything french-canadian in here, any UTF-8 locale will work. Here’s how these programs run on coliru with American English UTF-8:
wide char:
http://coliru.stacked-crooked.com/a/0bce63e9beb5ce05
strings:
http://coliru.stacked-crooked.com/a/2d88de701da9b81f
Last edited on
Topic archived. No new replies allowed.