aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/BunString.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bun.js/bindings/BunString.cpp')
-rw-r--r--src/bun.js/bindings/BunString.cpp40
1 files changed, 19 insertions, 21 deletions
diff --git a/src/bun.js/bindings/BunString.cpp b/src/bun.js/bindings/BunString.cpp
index 416d5d334..99fd02175 100644
--- a/src/bun.js/bindings/BunString.cpp
+++ b/src/bun.js/bindings/BunString.cpp
@@ -3,12 +3,13 @@
#include "JavaScriptCore/JSCJSValueInlines.h"
#include "helpers.h"
#include "simdutf.h"
-#include "wtf/text/ExternalStringImpl.h"
+#include "wtf/Seconds.h"
#include "GCDefferalContext.h"
#include <JavaScriptCore/JSONObject.h>
#include <wtf/text/AtomString.h>
using namespace JSC;
+extern "C" BunString BunString__fromBytes(const char* bytes, size_t length);
extern "C" bool Bun__WTFStringImpl__hasPrefix(const WTF::StringImpl* impl, const char* bytes, size_t length)
{
@@ -74,7 +75,10 @@ JSC::JSValue toJS(JSC::JSGlobalObject* globalObject, BunString bunString, size_t
#endif
return jsSubstring(globalObject, jsUndefined(), Bun::toWTFString(bunString), 0, length);
}
-
+BunString toString(const char* bytes, size_t length)
+{
+ return BunString__fromBytes(bytes, length);
+}
WTF::String toWTFString(const BunString& bunString)
{
if (bunString.tag == BunStringTag::ZigString) {
@@ -190,22 +194,6 @@ BunString toStringRef(WTF::StringImpl* wtfString)
return { BunStringTag::WTFStringImpl, { .wtf = wtfString } };
}
-BunString fromString(WTF::String& wtfString)
-{
- if (wtfString.isEmpty())
- return { BunStringTag::Empty };
-
- return { BunStringTag::WTFStringImpl, { .wtf = wtfString.impl() } };
-}
-
-BunString fromString(WTF::StringImpl* wtfString)
-{
- if (wtfString->isEmpty())
- return { BunStringTag::Empty };
-
- return { BunStringTag::WTFStringImpl, { .wtf = wtfString } };
-}
-
}
extern "C" JSC::EncodedJSValue BunString__toJS(JSC::JSGlobalObject* globalObject, BunString* bunString)
@@ -252,7 +240,7 @@ extern "C" BunString BunString__fromUTF8(const char* bytes, size_t length)
auto str = WTF::String::fromUTF8ReplacingInvalidSequences(reinterpret_cast<const LChar*>(bytes), length);
str.impl()->ref();
- return Bun::fromString(str);
+ return Bun::toString(str);
}
extern "C" BunString BunString__fromLatin1(const char* bytes, size_t length)
@@ -381,7 +369,17 @@ extern "C" BunString URL__getHref(BunString* input)
return Bun::toStringRef(url.string());
}
-extern "C" BunString URL__getHrefJoin(BunString* baseStr, BunString *relativeStr)
+extern "C" BunString URL__pathFromFileURL(BunString* input)
+{
+ auto&& str = Bun::toWTFString(*input);
+ auto url = WTF::URL(str);
+ if (!url.isValid() || url.isEmpty())
+ return { BunStringTag::Dead };
+
+ return Bun::toStringRef(url.fileSystemPath());
+}
+
+extern "C" BunString URL__getHrefJoin(BunString* baseStr, BunString* relativeStr)
{
auto base = Bun::toWTFString(*baseStr);
auto relative = Bun::toWTFString(*relativeStr);
@@ -455,4 +453,4 @@ extern "C" uint32_t URL__port(WTF::URL* url)
extern "C" BunString URL__pathname(WTF::URL* url)
{
return Bun::toStringRef(url->path().toStringWithoutCopying());
-} \ No newline at end of file
+}