65c332bd36
git-svn-id: svn://kolibrios.org@7983 a494cfbc-eb01-0410-851d-a64ba20cac60
76 lines
2.0 KiB
Plaintext
76 lines
2.0 KiB
Plaintext
(*
|
|
Copyright 2013, 2017, 2018, 2020 Anton Krotov
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*)
|
|
|
|
MODULE Utils;
|
|
|
|
IMPORT WINAPI;
|
|
|
|
PROCEDURE PutSeed*(seed: INTEGER);
|
|
BEGIN
|
|
WINAPI.srand(seed)
|
|
END PutSeed;
|
|
|
|
PROCEDURE Rnd*(range : INTEGER): INTEGER;
|
|
RETURN WINAPI.rand() MOD range
|
|
END Rnd;
|
|
|
|
PROCEDURE Utf8To16*(source: ARRAY OF CHAR; VAR dest: ARRAY OF CHAR): INTEGER;
|
|
VAR i, j, L, u, N: INTEGER;
|
|
BEGIN
|
|
L := LEN(source);
|
|
N := LEN(dest);
|
|
N := N - N MOD 2 - 1;
|
|
i := 0;
|
|
j := 0;
|
|
WHILE (i < L) & (j < N) & (source[i] # 0X) DO
|
|
CASE source[i] OF
|
|
|00X..7FX: u := ORD(source[i]);
|
|
|0C1X..0DFX:
|
|
u := LSL(ORD(source[i]) - 0C0H, 6);
|
|
IF i + 1 < L THEN
|
|
u := u + ROR(LSL(ORD(source[i + 1]), 26), 26);
|
|
INC(i)
|
|
END
|
|
|0E1X..0EFX:
|
|
u := LSL(ORD(source[i]) - 0E0H, 12);
|
|
IF i + 1 < L THEN
|
|
u := u + ROR(LSL(ORD(source[i + 1]), 26), 20);
|
|
INC(i)
|
|
END;
|
|
IF i + 1 < L THEN
|
|
u := u + ROR(LSL(ORD(source[i + 1]), 26), 26);
|
|
INC(i)
|
|
END
|
|
(* |0F1X..0F7X:
|
|
|0F9X..0FBX:
|
|
|0FDX:*)
|
|
ELSE
|
|
END;
|
|
INC(i);
|
|
dest[j] := CHR(u MOD 256);
|
|
INC(j);
|
|
dest[j] := CHR(u DIV 256);
|
|
INC(j);
|
|
END;
|
|
IF j < N THEN
|
|
dest[j] := 0X;
|
|
dest[j + 1] := 0X
|
|
END
|
|
RETURN j DIV 2
|
|
END Utf8To16;
|
|
|
|
END Utils. |