Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e4d609c
Add new encoding tests and implementation
Dec 22, 2025
7bc2d4e
Remove old marshal stuff and return an empty string instead of throwing
Dec 22, 2025
6ea2cc2
update tests
Dec 22, 2025
c39a54c
Case change
Dec 23, 2025
bbc622b
Update utf16 codepoint encoder
Dec 23, 2025
bfe921d
Add some extra functions
Dec 23, 2025
f9fb825
copyTo function for view
Dec 23, 2025
12f7a7b
single bounds check for utf8 encode
Dec 23, 2025
f37b1b9
marshal writes
Dec 23, 2025
6384c45
remove some conversion issues
Dec 23, 2025
be9ff94
Remove un-needed cast
Dec 23, 2025
6ff0e28
Remove questionable implicit view to pointer conversions
Dec 23, 2025
03a98d2
int returns
Dec 23, 2025
c006fb4
switch to a dedicated codepoint function for utf16
Dec 23, 2025
4b5e40a
move to a dedicated codepoint function for utf8 as well
Dec 23, 2025
485e8b7
Fix incorrect index reuse
Dec 24, 2025
3dbceb9
Add new view extension cstring function tests
Dec 24, 2025
74e7e57
Add a smart strings guard
Dec 24, 2025
2078eae
const view
Dec 25, 2025
db7a3bb
const ref marshal read and writes
Dec 25, 2025
819044e
more const ref and less object copying
Dec 26, 2025
16078b9
Fix index reuse issue
Dec 26, 2025
695e134
separate build xml for encoding
Dec 27, 2025
111b3ba
Don't return hx::Throw result in non smart string case
Dec 27, 2025
ed3e568
Revert "separate build xml for encoding"
Dec 27, 2025
d477f6d
better smart string handling and shuffle some functions in lower hxcpp
Dec 27, 2025
0ce64e2
Revert some version guards
Dec 28, 2025
e7d9ba4
Add pointer check define
Dec 28, 2025
7fa0fae
Merge branch 'master' into cpp_encoding
Dec 28, 2025
e50dab9
I don't understand why this is needed
Dec 28, 2025
d31ea3a
remove addition since there must be something else weird going on
Dec 28, 2025
d13d5a8
Could it really be this?
Jan 2, 2026
8a7c915
Dynamic char32_t support
Jan 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
406 changes: 406 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions include/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ template<> struct ReturnNull<float> { typedef Dynamic type; };
template<> struct ReturnNull<bool> { typedef Dynamic type; };
template<> struct ReturnNull<char> { typedef Dynamic type; };
template<> struct ReturnNull<char16_t> { typedef Dynamic type; };
template<> struct ReturnNull<char32_t> { typedef Dynamic type; };
template<> struct ReturnNull<signed char> { typedef Dynamic type; };
template<> struct ReturnNull<unsigned char> { typedef Dynamic type; };
template<> struct ReturnNull<short> { typedef Dynamic type; };
Expand Down Expand Up @@ -433,6 +434,7 @@ template<> struct ArrayClassId<signed char> { enum { id=hx::clsIdArrayByte }; };
template<> struct ArrayClassId<unsigned short> { enum { id=hx::clsIdArrayShort }; };
template<> struct ArrayClassId<signed short> { enum { id=hx::clsIdArrayShort }; };
template<> struct ArrayClassId<char16_t> { enum { id = hx::clsIdArrayShort }; };
template<> struct ArrayClassId<char32_t> { enum { id = hx::clsIdArrayInt }; };
template<> struct ArrayClassId<unsigned int> { enum { id=hx::clsIdArrayInt }; };
template<> struct ArrayClassId<signed int> { enum { id=hx::clsIdArrayInt }; };
template<> struct ArrayClassId<float> { enum { id=hx::clsIdArrayFloat32 }; };
Expand Down
8 changes: 8 additions & 0 deletions include/Dynamic.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic : public hx::ObjectPtr<hx::Object>
Dynamic(unsigned char inVal);
Dynamic(signed char inVal);
Dynamic(char16_t inVal);
Dynamic(char32_t inVal);
Dynamic(const cpp::CppInt32__ &inVal);
Dynamic(bool inVal);
Dynamic(double inVal);
Expand Down Expand Up @@ -73,6 +74,7 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic : public hx::ObjectPtr<hx::Object>
inline operator char () const { return mPtr ? mPtr->__ToInt() : 0; }
inline operator signed char () const { return mPtr ? mPtr->__ToInt() : 0; }
inline operator char16_t () const { return mPtr ? mPtr->__ToInt() : 0; }
inline operator char32_t () const { return mPtr ? mPtr->__ToInt() : 0; }
inline operator bool() const { return mPtr && mPtr->__ToInt(); }
inline operator cpp::Int64() const { return mPtr ? mPtr->__ToInt64() : 0; }
inline operator cpp::UInt64() const { return mPtr ? mPtr->__ToInt64() : 0; }
Expand Down Expand Up @@ -174,6 +176,7 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic : public hx::ObjectPtr<hx::Object>
bool operator op (signed char inRHS) const { return IsNumeric() && ((double)(*this) op (double)inRHS); } \
bool operator op (unsigned char inRHS) const { return IsNumeric() && ((double)(*this) op (double)inRHS); } \
bool operator op (char16_t inRHS) const { return IsNumeric() && ((double)(*this) op (double)inRHS); } \
bool operator op (char32_t inRHS) const { return IsNumeric() && ((double)(*this) op (double)inRHS); } \
bool operator op (bool inRHS) const { return IsBool() && ((double)(*this) op (double)inRHS); } \

bool operator != (const String &inRHS) const { return !mPtr || ((String)(*this) != inRHS); }
Expand All @@ -188,6 +191,7 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic : public hx::ObjectPtr<hx::Object>
bool operator != (signed char inRHS) const { return !IsNumeric() || ((double)(*this) != (double)inRHS); }
bool operator != (unsigned char inRHS) const { return !IsNumeric() || ((double)(*this) != (double)inRHS); }
bool operator != (char16_t inRHS) const { return !IsNumeric() || ((double)(*this) != (double)inRHS); }
bool operator != (char32_t inRHS) const { return !IsNumeric() || ((double)(*this) != (double)inRHS); }
bool operator != (bool inRHS) const { return !IsBool() || ((double)(*this) != (double)inRHS); }


Expand Down Expand Up @@ -234,6 +238,7 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic : public hx::ObjectPtr<hx::Object>
Dynamic operator+(const signed char &i) const;
Dynamic operator+(const unsigned char &i) const;
Dynamic operator+(const char16_t& i) const;
Dynamic operator+(const char32_t& i) const;
Dynamic operator+(const double &d) const;
Dynamic operator+(const float &d) const;
Dynamic operator+(const cpp::Variant &d) const;
Expand Down Expand Up @@ -277,6 +282,8 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES Dynamic : public hx::ObjectPtr<hx::Object>
{ return mPtr->__GetType()==vtInt ? Dynamic((int)(*this) op inRHS) : Dynamic((double)(*this) op inRHS); } \
Dynamic operator op (const char16_t &inRHS) const \
{ return mPtr->__GetType()==vtInt ? Dynamic((int)(*this) op inRHS) : Dynamic((double)(*this) op inRHS); } \
Dynamic operator op (const char32_t &inRHS) const \
{ return mPtr->__GetType()==vtInt ? Dynamic((int)(*this) op inRHS) : Dynamic((double)(*this) op inRHS); } \
Dynamic operator op (const cpp::Int64 &inRHS) const \
{ return Dynamic((double)(*this) op inRHS); } \
Dynamic operator op (const cpp::UInt64 &inRHS) const \
Expand Down Expand Up @@ -465,6 +472,7 @@ COMPARE_DYNAMIC_OP( > )
inline double operator op (const signed char &inLHS,const Dynamic &inRHS) { return inLHS op (double)inRHS; } \
inline double operator op (const unsigned char &inLHS,const Dynamic &inRHS) { return inLHS op (double)inRHS; } \
inline double operator op (const char16_t &inLHS,const Dynamic &inRHS) { return inLHS op (double)inRHS; } \
inline double operator op (const char32_t &inLHS,const Dynamic &inRHS) { return inLHS op (double)inRHS; } \

ARITH_DYNAMIC( - )
ARITH_DYNAMIC( + )
Expand Down
6 changes: 6 additions & 0 deletions include/cpp/Variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ namespace cpp
inline operator char () const { return asInt(); }
inline operator signed char () const { return asInt(); }
inline operator char16_t() const { return asInt(); }
inline operator char32_t() const { return asInt(); }
inline operator cpp::Int64 () const { return asInt64(); }
inline operator cpp::UInt64 () const { return asInt64(); }
inline bool operator !() const { return !asInt(); }
Expand Down Expand Up @@ -208,6 +209,7 @@ namespace cpp
inline bool operator op (signed char inRHS) const { return isNumeric() && (asDouble() op (double)inRHS); } \
inline bool operator op (unsigned char inRHS) const { return isNumeric() && (asDouble() op (double)inRHS); } \
inline bool operator op (char16_t inRHS) const { return isNumeric() && (asDouble() op (double)inRHS); } \
inline bool operator op (char32_t inRHS) const { return isNumeric() && (asDouble() op (double)inRHS); } \
inline bool operator op (bool inRHS) const { return isBool() && (asDouble() op (double)inRHS); } \
inline bool operator op (const Dynamic &inRHS) const { return Compare(inRHS) op 0; } \

Expand Down Expand Up @@ -281,6 +283,7 @@ namespace cpp
inline double operator op (const signed char &inLHS,const cpp::Variant &inRHS) { return inLHS op (double)inRHS; } \
inline double operator op (const unsigned char &inLHS,const cpp::Variant &inRHS) { return inLHS op (double)inRHS; } \
inline double operator op (const char16_t &inLHS,const cpp::Variant &inRHS) { return inLHS op (double)inRHS; } \
inline double operator op (const char32_t &inLHS,const cpp::Variant &inRHS) { return inLHS op (double)inRHS; } \
inline double operator op (const signed short &inLHS,const cpp::Variant &inRHS) { return inLHS op (double)inRHS; } \
inline double operator op (const unsigned short &inLHS,const cpp::Variant &inRHS) { return inLHS op (double)inRHS; } \
inline double operator op (const cpp::Int64 &inLHS,const cpp::Variant &inRHS) { return inLHS op (double)inRHS; } \
Expand Down Expand Up @@ -608,6 +611,7 @@ HX_VARIANT_OP_ISEQ(unsigned short)
HX_VARIANT_OP_ISEQ(signed char)
HX_VARIANT_OP_ISEQ(unsigned char)
HX_VARIANT_OP_ISEQ(char16_t)
HX_VARIANT_OP_ISEQ(char32_t)
HX_VARIANT_OP_ISEQ(bool)

inline bool operator < (bool inLHS,const cpp::Variant &inRHS) { return false; }
Expand Down Expand Up @@ -639,6 +643,8 @@ inline bool operator > (bool inLHS,const cpp::Variant &inRHS) { return false; }
{ return inRHS.isNumeric() && (inLHS op (double)inRHS); } \
inline bool operator op (char16_t inLHS,const ::cpp::Variant &inRHS) \
{ return inRHS.isNumeric() && (inLHS op (double)inRHS); } \
inline bool operator op (char32_t inLHS,const ::cpp::Variant &inRHS) \
{ return inRHS.isNumeric() && (inLHS op (double)inRHS); } \
inline bool operator op (const null &,const ::cpp::Variant &inRHS) \
{ return false; } \

Expand Down
24 changes: 24 additions & 0 deletions include/cpp/encoding/Ascii.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

namespace cpp
{
namespace encoding
{
struct Ascii final
{
static bool isEncoded(const String& string);

/// <summary>
/// Encode the provided string to ASCII bytes and write them to the buffer.
/// If the provided string is UTF16 encoded an exception is raised and nothing is written to the buffer.
/// </summary>
/// <returns>Number of chars written to the buffer.</returns>
static int64_t encode(const String& string, cpp::marshal::View<uint8_t> buffer);

/// <summary>
/// Create a string from the provided ASCII bytes.
/// </summary>
static String decode(cpp::marshal::View<uint8_t> string);
};
}
}
24 changes: 24 additions & 0 deletions include/cpp/encoding/Utf16.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

namespace cpp
{
namespace encoding
{
struct Utf16 final
{
static bool isEncoded(const String& string);

static int getByteCount(const char32_t& codepoint);
static int64_t getByteCount(const String& string);

static int getCharCount(const char32_t& codepoint);
static int64_t getCharCount(const String& string);

static int encode(const char32_t& codepoint, const cpp::marshal::View<uint8_t>& buffer);
static int64_t encode(const String& string, const cpp::marshal::View<uint8_t>& buffer);

static char32_t codepoint(const cpp::marshal::View<uint8_t>& buffer);
static String decode(const cpp::marshal::View<uint8_t>& buffer);
};
}
}
22 changes: 22 additions & 0 deletions include/cpp/encoding/Utf8.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

namespace cpp
{
namespace encoding
{
struct Utf8 final
{
static int getByteCount(const char32_t& codepoint);
static int64_t getByteCount(const String& string);

static int getCharCount(const char32_t& codepoint);
static int64_t getCharCount(const String& string);

static int encode(const char32_t& codepoint, const cpp::marshal::View<uint8_t>& buffer);
static int64_t encode(const String& string, const cpp::marshal::View<uint8_t>& buffer);

static char32_t codepoint(const cpp::marshal::View<uint8_t>& buffer);
static String decode(const cpp::marshal::View<uint8_t>& buffer);
};
}
}
Loading
Loading