mirror of
https://github.com/ETLCPP/etl.git
synced 2026-10-28 18:07:10 +08:00
Conditionally use wchar.h (#1115)
This commit is contained in:
parent
fe6fd35174
commit
a1367fc05f
@ -35,7 +35,6 @@ SOFTWARE.
|
||||
#include "algorithm.h"
|
||||
#include "iterator.h"
|
||||
#include "functional.h"
|
||||
#include "char_traits.h"
|
||||
#include "alignment.h"
|
||||
#include "array.h"
|
||||
#include "type_traits.h"
|
||||
@ -50,7 +49,10 @@ SOFTWARE.
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#if ETL_USING_LIBC_WCHAR_H
|
||||
#include <wchar.h>
|
||||
#endif
|
||||
|
||||
#if ETL_USING_STL && ETL_USING_CPP17
|
||||
#include <string_view>
|
||||
@ -2697,39 +2699,6 @@ namespace etl
|
||||
return to;
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// get_string_length, optimised for sizeof(U) == sizeof(char).
|
||||
//*********************************************************************
|
||||
template <typename U>
|
||||
static
|
||||
typename etl::enable_if<sizeof(U) == sizeof(char), size_t>::type
|
||||
get_string_length(const U* src)
|
||||
{
|
||||
return ::strlen(reinterpret_cast<const char*>(src));
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// get_string_length, optimised for sizeof(U) == sizeof(wchar_t).
|
||||
//*********************************************************************
|
||||
template <typename U>
|
||||
static
|
||||
typename etl::enable_if<sizeof(U) == sizeof(wchar_t), size_t>::type
|
||||
get_string_length(const U* src)
|
||||
{
|
||||
return ::wcslen(reinterpret_cast<const wchar_t*>(src));
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// get_string_length, optimised for anything else.
|
||||
//*********************************************************************
|
||||
template <typename U>
|
||||
static
|
||||
typename etl::enable_if<(sizeof(U) != sizeof(char)) && (sizeof(U) != sizeof(wchar_t)), size_t>::type
|
||||
get_string_length(const U* src)
|
||||
{
|
||||
return etl::strlen(src);
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Common implementation for 'assign' and 'append' for iterators.
|
||||
//*********************************************************************
|
||||
@ -2860,6 +2829,57 @@ namespace etl
|
||||
return size() - sz - etl::distance(rbegin(), iposition);
|
||||
}
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// get_string_length, optimised for sizeof(U) == sizeof(char).
|
||||
//*********************************************************************
|
||||
template <typename U>
|
||||
static
|
||||
typename etl::enable_if<sizeof(U) == sizeof(char), size_t>::type
|
||||
get_string_length(const U* str)
|
||||
{
|
||||
return ::strlen(reinterpret_cast<const char*>(str));
|
||||
}
|
||||
|
||||
#if ETL_USING_LIBC_WCHAR_H
|
||||
//*********************************************************************
|
||||
/// get_string_length, optimised for sizeof(U) == sizeof(wchar_t).
|
||||
//*********************************************************************
|
||||
template <typename U>
|
||||
static
|
||||
typename etl::enable_if<sizeof(U) == sizeof(wchar_t), size_t>::type
|
||||
get_string_length(const U* str)
|
||||
{
|
||||
return ::wcslen(reinterpret_cast<const wchar_t*>(str));
|
||||
}
|
||||
#endif
|
||||
|
||||
//*********************************************************************
|
||||
/// get_string_length, optimised for anything else.
|
||||
//*********************************************************************
|
||||
template <typename U>
|
||||
static
|
||||
#if ETL_USING_LIBC_WCHAR_H
|
||||
typename etl::enable_if<(sizeof(U) != sizeof(char)) && (sizeof(U) != sizeof(wchar_t)), size_t>::type
|
||||
#else
|
||||
typename etl::enable_if<(sizeof(U) != sizeof(char)), size_t>::type
|
||||
#endif
|
||||
get_string_length(const U* str)
|
||||
{
|
||||
if (str == ETL_NULLPTR)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const U* end = str;
|
||||
|
||||
while (*end++ != 0)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
return size_t(end - str) - 1;
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
|
||||
@ -449,6 +449,16 @@ SOFTWARE.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//*************************************
|
||||
// Determine if the ETL can use libc's wchar.h
|
||||
#if defined(ETL_NO_LIBC_WCHAR_H)
|
||||
#define ETL_USING_LIBC_WCHAR_H 0
|
||||
#define ETL_NOT_USING_LIBC_WCHAR_H 1
|
||||
#else
|
||||
#define ETL_USING_LIBC_WCHAR_H 1
|
||||
#define ETL_NOT_USING_LIBC_WCHAR_H 0
|
||||
#endif
|
||||
|
||||
//*************************************
|
||||
// Determine if the ETL should support atomics.
|
||||
#if defined(ETL_NO_ATOMICS) || \
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user