Skip to content

Commit

Permalink
Update import
Browse files Browse the repository at this point in the history
  • Loading branch information
vczh committed Feb 27, 2024
1 parent 3289f6d commit 6e33716
Show file tree
Hide file tree
Showing 6 changed files with 430 additions and 191 deletions.
10 changes: 8 additions & 2 deletions Import/Vlpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ String Conversions (buffer walkthrough)
if (d == nullptr)
{
while (reader.Read()) size++;
return reader.HasIllegalChar() ? -1 : size + 1;
return size + 1;
}
else
{
Expand All @@ -673,7 +673,7 @@ String Conversions (buffer walkthrough)
chars--;
if (!c) break;
}
return reader.HasIllegalChar() ? -1 : size;
return size;
}
}

Expand Down Expand Up @@ -926,6 +926,12 @@ Licensed under https://github.com/vczh-libraries/License

namespace vl
{
template class ObjectString<char>;
template class ObjectString<wchar_t>;
template class ObjectString<char8_t>;
template class ObjectString<char16_t>;
template class ObjectString<char32_t>;

#if defined VCZH_GCC
void _itoa_s(vint32_t value, char* buffer, size_t size, vint radix)
{
Expand Down
85 changes: 39 additions & 46 deletions Import/Vlpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -7090,6 +7090,12 @@ namespace vl
template<typename T>
const T ObjectString<T>::zero=0;

extern template class ObjectString<char>;
extern template class ObjectString<wchar_t>;
extern template class ObjectString<char8_t>;
extern template class ObjectString<char16_t>;
extern template class ObjectString<char32_t>;

/// <summary>Ansi string in local code page.</summary>
typedef ObjectString<char> AString;
/// <summary>Unicode string, UTF-16 on Windows, UTF-32 on Linux and macOS.</summary>
Expand Down Expand Up @@ -8690,8 +8696,17 @@ UtfConversion<T>
UtfReaderConsumer<TReader>
***********************************************************************/

template<typename TReader>
class UtfReaderConsumer : public Object
template<typename TInternalConsumer>
class UtfEmptyConsumerRedirection : public Object
{
public:
UtfEmptyConsumerRedirection(TInternalConsumer&)
{
}
};

template<typename TReader, template<typename> class TConsumerRedirection>
class UtfReaderConsumer : public TConsumerRedirection<typename TReader::ConsumerType>
{
protected:
TReader internalReader;
Expand All @@ -8704,13 +8719,9 @@ UtfReaderConsumer<TReader>
template<typename ...TArguments>
UtfReaderConsumer(TArguments&& ...arguments)
: internalReader(std::forward<TArguments&&>(arguments)...)
, TConsumerRedirection<typename TReader::ConsumerType>(internalReader)
{
}

bool HasIllegalChar() const
{
return internalReader.HasIllegalChar();
}
};

/***********************************************************************
Expand All @@ -8727,9 +8738,10 @@ UtfFrom32ReaderBase<T, TConsumer>

UtfCharCluster sourceCluster = { 0,0 };
vint readCounter = -1;
bool error = false;

public:
using ConsumerType = TConsumer;

template<typename ...TArguments>
UtfFrom32ReaderBase(TArguments&& ...arguments)
: TConsumer(std::forward<TArguments&&>(arguments)...)
Expand Down Expand Up @@ -8772,11 +8784,6 @@ UtfFrom32ReaderBase<T, TConsumer>
{
return sourceCluster;
}

bool HasIllegalChar() const
{
return error || TConsumer::HasIllegalChar();
}
};

/***********************************************************************
Expand All @@ -8792,9 +8799,10 @@ UtfTo32ReaderBase<T, TConsumer>

UtfCharCluster sourceCluster = { 0,0 };
vint readCounter = -1;
bool error = false;

public:
using ConsumerType = TConsumer;

template<typename ...TArguments>
UtfTo32ReaderBase(TArguments&& ...arguments)
: TConsumer(std::forward<TArguments&&>(arguments)...)
Expand Down Expand Up @@ -8852,11 +8860,6 @@ UtfTo32ReaderBase<T, TConsumer>
{
return sourceCluster;
}

bool HasIllegalChar() const
{
return error || TConsumer::HasIllegalChar();
}
};

/***********************************************************************
Expand All @@ -8866,10 +8869,12 @@ Utf32DirectReaderBase<TConsumer>
template<typename TConsumer>
class Utf32DirectReaderBase : public TConsumer
{
UtfCharCluster sourceCluster = { -1,1 };
vint readCounter = -1;
bool ended = false;

public:
using ConsumerType = TConsumer;

template<typename ...TArguments>
Utf32DirectReaderBase(TArguments&& ...arguments)
: TConsumer(std::forward<TArguments&&>(arguments)...)
Expand All @@ -8882,24 +8887,22 @@ Utf32DirectReaderBase<TConsumer>
static_assert(sizeof(dest) == sizeof(char32_t));
if (dest || !ended)
{
sourceCluster.index += 1;
if (!dest)
{
ended = true;
sourceCluster.size = 0;
}
readCounter++;
}
ended = !dest;
return static_cast<char32_t>(dest);
}

vint ReadingIndex() const
{
return sourceCluster.index;
return readCounter;
}

UtfCharCluster SourceCluster() const
{
return sourceCluster;
if (readCounter == -1) return { 0,0 };
if (ended) return { readCounter,0 };
return { readCounter,1 };
}
};

Expand All @@ -8910,10 +8913,10 @@ UtfToUtfReaderBase<TFrom, TTo, TConsumer>
template<typename TFrom, typename TTo>
struct UtfToUtfReaderSelector
{
template<typename TConsumer>
class Reader : public UtfFrom32ReaderBase<TTo, UtfReaderConsumer<UtfTo32ReaderBase<TFrom, TConsumer>>>
template<typename TConsumer, template<typename> class TConsumerRedirection>
class Reader : public UtfFrom32ReaderBase<TTo, UtfReaderConsumer<UtfTo32ReaderBase<TFrom, TConsumer>, TConsumerRedirection>>
{
using TBase = UtfFrom32ReaderBase<TTo, UtfReaderConsumer<UtfTo32ReaderBase<TFrom, TConsumer>>>;
using TBase = UtfFrom32ReaderBase<TTo, UtfReaderConsumer<UtfTo32ReaderBase<TFrom, TConsumer>, TConsumerRedirection>>;
public:
template<typename ...TArguments>
Reader(TArguments&& ...arguments)
Expand All @@ -8931,22 +8934,22 @@ UtfToUtfReaderBase<TFrom, TTo, TConsumer>
template<typename TTo>
struct UtfToUtfReaderSelector<char32_t, TTo>
{
template<typename TConsumer>
template<typename TConsumer, template<typename> class>
using Reader = UtfFrom32ReaderBase<TTo, TConsumer>;
};

template<typename TFrom>
struct UtfToUtfReaderSelector<TFrom, char32_t>
{
template<typename TConsumer>
template<typename TConsumer, template<typename> class>
using Reader = UtfTo32ReaderBase<TFrom, TConsumer>;
};

#define DEFINE_UTF32_DIRECT_READER(TFROM, TTO)\
template<>\
struct UtfToUtfReaderSelector<TFROM, TTO>\
{\
template<typename TConsumer>\
template<typename TConsumer, template<typename> class>\
using Reader = Utf32DirectReaderBase<TConsumer>;\
}\

Expand All @@ -8960,8 +8963,8 @@ UtfToUtfReaderBase<TFrom, TTo, TConsumer>

#undef DEFINE_UTF32_DIRECT_READER

template<typename TFrom, typename TTo, typename TConsumer>
using UtfToUtfReaderBase = typename UtfToUtfReaderSelector<TFrom, TTo>::template Reader<TConsumer>;
template<typename TFrom, typename TTo, typename TConsumer, template<typename> class TConsumerRedirection = UtfEmptyConsumerRedirection>
using UtfToUtfReaderBase = typename UtfToUtfReaderSelector<TFrom, TTo>::template Reader<TConsumer, TConsumerRedirection>;

/***********************************************************************
UtfStringConsumer<T>
Expand All @@ -8986,11 +8989,6 @@ UtfStringConsumer<T>
, consuming(_starting)
{
}

bool HasIllegalChar() const
{
return false;
}
};

template<typename TFrom, typename TTo>
Expand Down Expand Up @@ -9035,11 +9033,6 @@ UtfStringRangeConsumer<T>
, consuming(_starting)
{
}

bool HasIllegalChar() const
{
return false;
}
};

template<typename TFrom, typename TTo>
Expand Down
Loading

0 comments on commit 6e33716

Please sign in to comment.