From 891e4fd78907350e94a8be1976c1e121ecc5d5a4 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Fri, 26 May 2023 09:00:20 -0400 Subject: [PATCH] Minor lib changes --- BeefLibs/corlib/src/Span.bf | 6 ++++++ BeefLibs/corlib/src/String.bf | 6 ++++++ BeefLibs/curl/src/Curl.bf | 30 ++++++++++++++++++++++++++++++ BeefLibs/curl/src/Transfer.bf | 16 ++++++++++++++++ 4 files changed, 58 insertions(+) diff --git a/BeefLibs/corlib/src/Span.bf b/BeefLibs/corlib/src/Span.bf index 758f6e89..4c0f749e 100644 --- a/BeefLibs/corlib/src/Span.bf +++ b/BeefLibs/corlib/src/Span.bf @@ -295,6 +295,12 @@ namespace System return Span((uint8*)mPtr, mLength * sizeof(T)); } + public void Sort(Comparison comp) + { + var sorter = Sorter(Ptr, null, Length, comp); + sorter.[Friend]Sort(0, Length); + } + public Enumerator GetEnumerator() { return Enumerator(this); diff --git a/BeefLibs/corlib/src/String.bf b/BeefLibs/corlib/src/String.bf index b5e5d97e..0c9df151 100644 --- a/BeefLibs/corlib/src/String.bf +++ b/BeefLibs/corlib/src/String.bf @@ -3487,6 +3487,12 @@ namespace System mLength = length; } + public this(Span data) + { + mPtr = (.)data.Ptr; + mLength = data.Length; + } + public ref char8 this[int index] { [Checked] diff --git a/BeefLibs/curl/src/Curl.bf b/BeefLibs/curl/src/Curl.bf index 9cbd9f70..dfdb67b6 100644 --- a/BeefLibs/curl/src/Curl.bf +++ b/BeefLibs/curl/src/Curl.bf @@ -865,6 +865,15 @@ namespace CURL [CLink, CallingConvention(.Stdcall)] static extern void* curl_easy_init(); + [CLink, CallingConvention(.Stdcall)] + static extern void curl_free(void* ptr); + + [CLink, CallingConvention(.Stdcall)] + static extern char8* curl_easy_escape(void* curl, char8* str, int32 length); + + [CLink, CallingConvention(.Stdcall)] + static extern char8* curl_easy_unescape(void* curl, char8* input, int32 inlength, int32* outlength); + [CLink, CallingConvention(.Stdcall)] static extern int curl_easy_setopt(void* curl, int option, int optVal); @@ -984,5 +993,26 @@ namespace CURL { curl_slist_free_all(list); } + + public void Escape(StringView str, String outStr) + { + char8* ptr = curl_easy_escape(mCURL, str.Ptr, (.)str.Length); + if (ptr != null) + { + outStr.Append(ptr); + curl_free(ptr); + } + } + + public void Unescape(StringView str, String outStr) + { + int32 outLen = 0; + char8* ptr = curl_easy_unescape(mCURL, str.Ptr, (.)str.Length, &outLen); + if (ptr != null) + { + outStr.Append(ptr, outLen); + curl_free(ptr); + } + } } } \ No newline at end of file diff --git a/BeefLibs/curl/src/Transfer.bf b/BeefLibs/curl/src/Transfer.bf index eb9d37c9..e9c2846d 100644 --- a/BeefLibs/curl/src/Transfer.bf +++ b/BeefLibs/curl/src/Transfer.bf @@ -161,6 +161,22 @@ namespace CURL mCurl.SetOpt(.Postfields, param); } + public void Escape(StringView str, String outStr) + { + mCurl.Escape(str, outStr); + } + + public void Unescape(StringView str, String outStr) + { + int startPos = outStr.Length; + + mCurl.Unescape(str, outStr); + + for (int i = startPos; i < outStr.Length; i++) + if (outStr[i] == '+') + outStr[i] = ' '; + } + public Result> Perform() { if (mHeaderList != null)