flang the compiler proves your program cannot hang 0.9.0 GitHub Try in the browserTry it Русский

UTF-8

Text to bytes and bytes back to code points — UTF-8, RFC 3629.

Import:

  использует «UTF-8»

Example

File example.flang:

модуль «Пример»
  использует «UTF-8»

тотальная функция «Вызов из примера»
  возвращает список числа
  пример «Латиница — байт в байт с ASCII»
    ожидается [77, 97, 110]
  «Байты текста» от "Man"
$ flang test example.flang
example.flang: примеров 87, прошло 87, не прошло 0

The command runs the tests of the module and the test in the file: 87 in total. The value on the ожидается line comes from the test of «Байты текста» in the module source.

Functions

Functions to call: 12; internal: 4, listed at the end of the page.

Every postcondition has a status: proved — holds for any arguments; checked on tests only — no violation on the values from the tests, other arguments are checked at run time; not proved — there is no proof, the condition is checked at run time.

Used most often in the examples and in other modules: «Байты текста», «Кодовые точки из байтов», «Досыпать байты», «Кодовые точки текста», «Байты кодовой точки», «Текст без одиноких суррогатов».

«Байты кодовой точки»

принимает код: число
возвращает список числа

Test from the module: given код = 65 returns [65].

«Досыпать байты»

принимает готовые: список числа, добавка: список числа
возвращает список числа

Test from the module: given готовые = [1], добавка = [2, 3] returns [1, 2, 3].

«Кодовые точки текста»

принимает текст: строка
возвращает список числа

Test from the module: given текст = "Ab" returns [65, 98].

«Байты текста»

принимает текст: строка
возвращает список числа

Test from the module: given текст = "Man" returns [77, 97, 110].

«Текст без одиноких суррогатов»

принимает текст: строка
возвращает признак

Test from the module: given текст = "Мир" returns да.

«Кодовые точки из байтов»

принимает байты: список числа
возвращает список числа

Test from the module: given байты = [77, 97, 110] returns [77, 97, 110].

Other functions

No other library module and no example in the repository calls these functions. The functions above are called.

«Одинокий суррогат»

принимает код: число
возвращает признак

Test from the module: given код = 55357 returns да.

«Байтов в точке»

принимает код: число
возвращает число

Test from the module: given код = 127 returns 1.

«Длина в байтах»

принимает текст: строка
возвращает число

Test from the module: given текст = "Man" returns 3.

«Байты годны как UTF-8»

принимает байты: список числа
возвращает признак

Test from the module: given байты = [77, 97, 110] returns да.

«Круговой ход держится»

принимает текст: строка
возвращает признак

Test from the module: given текст = "Man" returns да.

«Списки точек равны»

принимает первый: список числа, второй: список числа
возвращает признак

Test from the module: given первый = [1, 2], второй = [1, 2] returns да.

Theorems and claims

flang check verifies them with the module.

Internal functions and types

Library modules declare no экспортирует list, so any function can be called. Internal here means by naming convention: a function «Шаг …» is a fold step, a type «Ход …» is a fold state, and so are functions that take or return such a type.

Show the list
тип «Ход разбора utf8»
«Начало разбора utf8»: → «Ход разбора utf8»
«Начать байт»: (точки: список числа, замещений: число,
    байт: число) → «Ход разбора utf8»
«Шаг разбора utf8»: (ход: «Ход разбора utf8», байт: число) → «Ход разбора utf8»
«Закрыть разбор utf8»: (ход: «Ход разбора utf8») → список числа

Source: flang/stdlib/utf8.flang. All modules: Standard library.