File tree 1 file changed +21
-0
lines changed
1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -1876,6 +1876,7 @@ TPythonEngine = class(TPythonInterface)
1876
1876
function PyUnicodeFromString (const AString : UnicodeString) : PPyObject; overload;
1877
1877
function PyUnicodeFromString (const AString: AnsiString): PPyObject; overload;
1878
1878
function PyUnicodeAsString ( obj : PPyObject ) : UnicodeString;
1879
+ function PyUnicodeAsUTF8String ( obj : PPyObject ) : RawByteString;
1879
1880
function PyBytesAsAnsiString ( obj : PPyObject ) : AnsiString;
1880
1881
1881
1882
// Public Properties
@@ -5616,6 +5617,26 @@ function TPythonEngine.PyUnicodeAsString( obj : PPyObject ) : UnicodeString;
5616
5617
raise EPythonError.Create(' PyUnicodeAsString expects a Unicode Python object' );
5617
5618
end ;
5618
5619
5620
+ function TPythonEngine.PyUnicodeAsUTF8String ( obj : PPyObject ) : RawByteString;
5621
+ var
5622
+ buffer: PAnsiChar;
5623
+ size: NativeInt;
5624
+ begin
5625
+ if PyUnicode_Check(obj) then
5626
+ begin
5627
+ Result := ' ' ;
5628
+ buffer := PyUnicode_AsUTF8AndSize(obj, @size);
5629
+ if Assigned(buffer) then
5630
+ SetString(Result, buffer, size)
5631
+ else
5632
+ Result := ' ' ;
5633
+ SetCodePage(Result, CP_UTF8, False);
5634
+ end
5635
+ else
5636
+ raise EPythonError.Create(' PyUnicodeAsUTF8String expects a Unicode Python object' );
5637
+ end ;
5638
+
5639
+
5619
5640
function TPythonEngine.PyUnicodeFromString (const AString : UnicodeString) : PPyObject;
5620
5641
{ $IFDEF POSIX}
5621
5642
var
You can’t perform that action at this time.
0 commit comments