Skip to content

Commit c50f689

Browse files
pmderodatraph-amiard
authored andcommitted
Langkit_Support.Text: add a function to decode strings to text
TN: RA02-064
1 parent 2055c45 commit c50f689

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

langkit/support/langkit_support-text.adb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,21 @@ package body Langkit_Support.Text is
164164
From_Code => Text_Charset);
165165
end Encode;
166166

167+
------------
168+
-- Decode --
169+
------------
170+
171+
function Decode (S : String; Charset : String) return Text_Type is
172+
Result : constant String := GNATCOLL.Iconv.Iconv
173+
(Input => S,
174+
To_Code => Text_Charset,
175+
From_Code => Charset);
176+
pragma Assert (S'Length mod 4 = 0);
177+
178+
Text_Result : constant Text_Type (1 .. Result'Length / 4)
179+
with Import, Address => Result'Address;
180+
begin
181+
return Text_Result;
182+
end Decode;
183+
167184
end Langkit_Support.Text;

langkit/support/langkit_support-text.ads

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ package Langkit_Support.Text is
6262
function Encode (Text : Text_Type; Charset : String) return String;
6363
-- Use GNATCOLL.Iconv to convert Text into a String encoded using the given
6464
-- Charset. Note that this is only a convenience wrapper around
65-
-- GNATCOLL.Iconv: for instance, if performance needs dictatet to avoid
65+
-- GNATCOLL.Iconv: for instance, if performance needs dictate to avoid
6666
-- secondary stack usage, please use directly GNATCOLL.Iconv.
6767

68+
function Decode (S : String; Charset : String) return Text_Type;
69+
-- Likewise, but convert a string to text
70+
6871
type Text_Access is access all Text_Type;
6972
type Text_Cst_Access is access constant Text_Type;
7073

0 commit comments

Comments
 (0)