Browse Source

Pascal Scripting change: Added support functions UTF8Encode and UTF8Decode to encode a Unicode string into a UTF-8 encoded ANSI string and vice versa.

Martijn Laan 1 year ago
parent
commit
0d271c81f3

+ 10 - 0
ISHelp/isxfunc.xml

@@ -1141,6 +1141,16 @@ GetDateTimeString('dd/mm/yyyy hh:nn:ss', '-', ':');
         <prototype>procedure OemToCharBuff(var S: AnsiString);</prototype>
         <description><p>Translates a string with characters from the OEM-defined character set into an ANSI string.</p></description>
       </function>
+      <function>
+        <name>Utf8Encode</name>
+        <prototype>function Utf8Encode(const S: String): AnsiString;</prototype>
+        <description><p>Encodes a Unicode string into a UTF-8 encoded ANSI string.</p></description>
+      </function>
+      <function>
+        <name>Utf8Decode</name>
+        <prototype>function Utf8Decode(const S: AnsiString): String;</prototype>
+        <description><p>Decodes a UTF-8 encoded ANSI string into a Unicode string.</p></description>
+      </function>
     </subcategory>
     <subcategory>
       <function>

+ 1 - 1
Projects/Src/FileClass.pas

@@ -565,7 +565,7 @@ end;
 
 procedure TTextFileWriter.Write(const S: String);
 begin
-  DoWrite(UTF8Encode(S), True);
+  DoWrite(Utf8Encode(S), True);
 end;
 
 procedure TTextFileWriter.WriteLine(const S: String);

+ 1 - 1
Projects/Src/ScriptCompiler.pas

@@ -463,7 +463,7 @@ var
 begin
   Result := False;
 
-  FScriptText := UTF8Encode(ScriptText);
+  FScriptText := Utf8Encode(ScriptText);
 
   for I := 0 to FExports.Count-1 do
     TScriptExport(FExports[I]).Exported := False;

+ 4 - 2
Projects/Src/ScriptFunc.pas

@@ -232,13 +232,15 @@ const
   );
 
   { System }
-  SystemTable: array [0..4] of AnsiString =
+  SystemTable: array [0..6] of AnsiString =
   (
     'function Random(const Range: Integer): Integer;',
     'function FileSize(const Name: String; var Size: Integer): Boolean;',
     'function FileSize64(const Name: String; var Size: Int64): Boolean;',
     'procedure Set8087CW(NewCW: Word);',
-    'function Get8087CW: Word;'
+    'function Get8087CW: Word;',
+    'function UTF8Encode(const S: String): AnsiString;',
+    'function UTF8Decode(const S: AnsiString): String;'
   );
 
   { SysUtils }

+ 4 - 0
Projects/Src/ScriptFunc_R.pas

@@ -1221,6 +1221,10 @@ begin
     Set8087CW(Stack.GetInt(PStart));
   end else if Proc.Name = 'GET8087CW' then begin
     Stack.SetInt(PStart, Get8087CW);
+  end else if Proc.Name = 'UTF8ENCODE' then begin
+    StackSetAnsiString(Stack, PStart, Utf8Encode(Stack.GetString(PStart-1)));
+  end else if Proc.Name = 'UTF8DECODE' then begin
+    Stack.SetString(PStart, Utf8Decode(StackGetAnsiString(Stack, PStart-1)));
   end else
     Result := False;
 end;

+ 6 - 1
whatsnew.htm

@@ -142,7 +142,12 @@ end;</pre>
   <li>During startup Setup would always ask Windows to create any missing <tt>{usercf}</tt>, <tt>{userpf}</tt>, and <tt>{usersavedgames}</tt> folders. It no longer does until the script asks for the folder. Note that scripts running in administrative install mode should not do this because it violates the <a href="ishelp/index.php?topic=setup_useduserareaswarning">used user areas warning</a>.</li>
   <li>Added support for IIS group users identifiers (<tt>iisiusrs</tt>) for use in <tt>Permissions</tt> parameters.</li> 
   <li>ISPP change: Support function <tt>Exec</tt> no longer requires the filename parameter to be quoted if it contains spaces. Additionally it now supports &quot;&gt;&quot; as a filename and now includes special platform-independent support for .bat and .cmd files, both just like for example the <tt>[Run]</tt> section.</li>
-  <li>Pascal Scripting change: Type <tt>TShellFolderID</tt> was removed because it wasn't used by any support function.</li>
+  <li>Pascal Scripting changes: 
+    <ul>
+    <li>Added support functions <tt>UTF8Encode</tt> and <tt>UTF8Decode</tt> to encode a Unicode string into a UTF-8 encoded ANSI string and vice versa.</li>
+    <li>Type <tt>TShellFolderID</tt> was removed because it wasn't used by any support function.</li>
+    </ul>
+  </li>
   <li>Improved the icons used by the <i>Select Language</i> dialog and the <i>Select Destination Location</i>, <i>Select Start Menu Folder</i>, and <i>Preparing to Install</i> wizard pages at 150% DPI and at 200% DPI.</li>
   <li>Added modern icons to the MyProg example executables, now compiled with Visual Studio 2022.</li>
   <li>Added official Korean translation.</li>