-
template <typename ContainerType_, typename StrType_>
ContainerType_ FindAllStr(const StrType_& str, const StrType_& find_str)
표준 문자열 객체(std::string, std::wstring, std::u16string, std::u32string 의 객체) str의 내용에서 발견되는 find_str을 모두 찾아 그 위치(인덱스)를 반환합니다.
템플릿 타입인수 ContainerType_으로, 정수 계열 타입을 담고 push_back을 지원하는 표준 컨테이너(std::vector, std::list 등)를 넘겨줘야 합니다.
ContainerType_의 객체에 검색한 인덱스를 모두 담아 반환합니다.
-
template bool NextChar(...)
멀티바이트 문자가 포함된 표준 문자열 객체에서, 다음 문자의 인덱스를 구하는 함수입니다(부가기능 있음). NextChar 함수는 두 개의 오버로딩 버전이 제공됩니다.
- template <typename CharType_, typename EncodingType_>
- std::enable_if_t<
- IsCharacter<std::decay_t<CharType_>>::value &&
- encoding::IsEncodingType<std::decay_t<EncodingType_>>::value,
- bool
- >
- NextChar(
- const CharType_* str,
- Mchar<EncodingType_>& mch,
- size_t& idx,
- const CheckCharFuncType& check_char = CheckCharFuncType()
- );
-
-
-
-
- template <typename StrType_, typename EncodingType_>
- inline std::enable_if_t<
- IsString<std::decay_t<StrType_>>::value&&
- encoding::IsEncodingType<std::decay_t<EncodingType_>>::value,
- bool
- >
- NextChar(
- const StrType_& str,
- Mchar<EncodingType_>& mch,
- size_t& idx,
- const CheckCharFuncType& check_char = CheckCharFuncType()
- );
-
-
두 오버로딩 버전 모두,
check_char을 통해 지정된 인코딩 단위전략으로 해석이 불가능한 문자를 처리하는 함수를 지정할 수 있습니다. CheckCharFuncType에 대한 자세한 설명은 아래의 참고자료에서 볼 수 있습니다.
참고자료
-
template <typename EncodingType_, typename StrType_>
size_t NextNChar(
const StrType_& str,
size_t n,
size_t& idx,
const CheckCharFuncType& check_char = CheckCharFuncType()
)
표준 문자열 타입(StrType_) 객체 str의 idx(초기값) 위치부터, n개의 (멀티바이트) 문자 다음의 문자를 가리키는 인덱스를,
idx 래퍼런스(매개변수)를 통해 구합니다. str의 idx(초기값) 위치부터 끝까지의 문자 수가 n개보다 적은 경우
(n - "str의 idx위치부터 끝까지, 포함된 문자 개수")를, 그렇지 않은 경우 0을 반환합니다. 템플릿 매개변수
EncodingType_에는 표준 문자열 타앱 객체 str의 인코딩에 해당하는 인코딩 단위전략을 넘겨 줘야 합니다.
StrType_이 std::string(1 바이트 문자 타입 기반)이 아닌 경우에는, EncodingType_에 어떤
인코딩 단위전략을 넘겨줘도 무방합니다.
check_char을 통해 지정된 인코딩 단위전략으로 해석이 불가능한 문자를 처리하는 함수를 지정할 수 있습니다. CheckCharFuncType에 대한 자세한 설명은 아래의 참고자료에서 볼 수 있습니다.
참고자료
-
template <typename EncodingType_, typename StrType_>
size_t CountChar(
const StrType_& str,
size_t begin = 0,
size_t end = ~static_cast<size_t>(0),
const CheckCharFuncType& check_char = CheckCharFuncType()
)
표준 문자열 타입(StrType_) 객체 str의 begin ~ end 인덱스 범위에 포함된 (멀티바이트) 문자의 개수를 구합니다.
템플릿 매개변수 EncodingType_에는 표준 문자열 타입 객체 str의 인코딩에 해당하는 인코딩 단위전략을 넘겨줘야
합니다. StrType_이 std::string(1 바이트 문자 타입 기반)이 아닌 경우에는, EncodingType_에
어떤 인코딩 단위전략을 넘겨줘도 무방합니다.
check_char을 통해 지정된 인코딩 단위전략으로 해석이 불가능한 문자를 처리하는 함수를 지정할 수 있습니다. CheckCharFuncType에 대한 자세한 설명은 아래의 참고자료에서 볼 수 있습니다.
참고자료
-
template <typename EncodingType_, typename StrType_>
size_t FindInvalidChar(const StrType_& str, size_t begin = 0, size_t end = ~static_cast<size_t>(0))
표준 문자열 타입(StrType_) 객체 str의 begin ~ end 인덱스 범위에서 처음으로 발견되는,
지정한 인코딩(EncodingType_)으로 해석할 수 없는 문자의 idx를 찾아 반환합니다.
StrType_이 std::string(1 바이트 문자 타입 기반)이 아닌 경우에는, EncodingType_에 어떤
인코딩 단위전략을 넘겨줘도 무방합니다.
-
template <typename EncodingType_, typename StrType_>
size_t CountInvalidChar(
const StrType_& str,
size_t begin = 0,
size_t end = ~static_cast<size_t>(0)
)
표준 문자열 타입(StrType_) 객체 str의 begin ~ end 인덱스 범위에서, 지정한 인코딩(EncodingType_)으로
해석할 수 없는 문자의 개수를 구합니다. StrType_이 std::string(1 바이트 문자 타입 기반)이 아닌 경우에는,
EncodingType_에 어떤 인코딩 단위전략을 넘겨줘도 무방합니다.
-
template <typename StrType_>
std::ostream& operator <<(std::ostream& o, const StrType_& str)
std::string이 아닌 표준 문자열 타입(std::u16string, std::u32string 등의
2 바이트 이상의 문자 타입을 사용하는 표준 문자열 타입) 객체를 DefaultEncoding(UTF-8) 인코딩(인코딩 기본값)으로
변환한 뒤 char(1바이트) 기반 std::ostream 객체를 통해 출력합니다.
-
template <typename EncodingType_, typename DstStrType_, typename SrcStrType_>
DstStrType_ ConvertString(
const SrcStrType_& str,
const CheckCharFuncType& check_char = CheckCharFuncType()
)
표준 문자열 타입 객체간 변환을 해 주는 함수 템플릿 입니다. 변환될 문자열 객체나 변환할 문자열 객체 중 하나가
std::string 타입인 경우, 이 객체에 사용할 인코딩 단위전략을 템플릿 인수 EncodingType_에 넘겨줍니다.
SrcStrType_과 DstStrType_이 모두 std::string(1 바이트 문자 타입 기반)이 아닌 경우에는 어떤
인코딩 단위전략을 사용하든 무방합니다. 그리고, 변환될 문자열 타입을 템플릿 인수 DstStrType_에 넘겨줍니다.
그러면, SrcStrType_ 타입 객체 str을 DstStrType_ 타입 객체로 변환하여 반환합니다.
check_char을 통해 지정된 인코딩 단위전략으로 해석이 불가능한 문자를 처리하는 함수를 지정할 수 있습니다. CheckCharFuncType에 대한 자세한 설명은 아래의 참고자료에서 볼 수 있습니다.
참고자료
-
template <typename DstEncoding_, typename SrcEncoding_>
std::string ConvertEncoding(
const std::string& str,
bool with_bom,
const CheckCharFuncType& check_char = CheckCharFuncType()
)
표준 문자열 타입(std::string) 객체의 인코딩을 변환합니다. 매개변수 str(변환할 문자열)의 인코딩에 해당하는 인코딩
단위전략을 템플릿 타입인수 SrcEncoding_에 넘겨줍니다. 그리고 변환될 문자열의 인코딩에 해당하는 인코딩
단위전략을 템플릿 타입인수 DstEncoding_에 넘겨줍니다. 변환될 문자열의 첫 문자에 BOM(Byte Order Mark)
을 넣는다면 with_bom 매개변수에 true를, 그렇지 않으면 false를 넘겨줍니다. BOM이 존재하지 않는 인코딩
사용 시 with_bom 매개변수에 true를 넘겨주면, U+FFFD 또는 물음표('?')가 BOM 대신 삽입됩니다.
check_char을 통해 지정된 인코딩 단위전략으로 해석이 불가능한 문자를 처리하는 함수를 지정할 수 있습니다. CheckCharFuncType에 대한 자세한 설명은 아래의 참고자료에서 볼 수 있습니다.
참고자료
-
template <typename StrType_>
auto operator *(...)
표준 문자열 타입(std::string, std::u16string, std::u32string 등) 객체를 n 번 반복한
문자열을 구합니다. 교환법칙에 따라 매개변수의 순서가 반대인 오버로딩 버전을 제공합니다.
- template <typename StrType_>
- std::enable_if_t<IsString<std::decay_t<StrType_>>::value, StrType_>
- operator *(const StrType_& str, size_t n);
-
-
-
- template <typename StrType_>
- inline std::enable_if_t<IsString<std::decay_t<StrType_>>::value, StrType_>
- operator *(size_t n, const StrType_& str);
-
또한, Mchar 객체가 담고 있는 (멀티바이트) 문자 하나가 n번 반복된 문자열(std::string)을 구하는
오버로딩 버전도 제공됩니다. 이 오버로딩 버전 역시 교환법칙에 따라, 매개변수의 순서가 반대인 오버로딩 버전이
제공됩니다.
- template <typename EncodingType_>
- inline std::enable_if_t<encoding::IsEncodingType<std::decay_t<EncodingType_>>::value, std::string>
- operator *(const Mchar<EncodingType_>& mch, size_t n);
-
-
-
- template <typename EncodingType_>
- inline std::enable_if_t<encoding::IsEncodingType<std::decay_t<EncodingType_>>::value, std::string>
- operator *(size_t n, const Mchar<EncodingType_>& mch);
-
-
template <typename StrType_>
StrType_&& operator *=(StrType_&& str, size_t n)
표준 문자열 타입(std::string, std::u16string, std::u32string 등) 객체 str을
n 번 반복시켜 str 자신에 대입한 후, 그 객체를 그대로 반환합니다.
-
template <
typename LhsEncoding_,
typename RhsEncoding_,
typename LhsStrType_,
typename RhsStrType_
>
int UCompare(
const LhsStrType_& lhs,
const RhsStrType_& rhs,
const CheckCharFuncType& check_char = CheckCharFuncType()
)
표준 문자열 타입(std::string, std::u16string, std::u32string 등) 객체 lhs,와 rhs를
유니코드 오름차순 기준으로 비교하여 lhs가 rhs보다 앞에 오는 경우 -1, 뒤에 오는 경우 1, 같은 경우 0을 반환합니다.
템플릿 타입인수 LhsEncoding_에는 lhs의 인코딩 단위전략을, RhsEncoding_에는 rhs의 인코딩 단위전략을
넘겨줍니다. lhs(rhs)가 std::string(1 바이트 문자 타입 기반) 타입이 아니라 다른 표준 문자열 타입인 경우,
LhsEncoding_(RhsEncoding_)에 어떤 인코딩 단위전략을 넘겨줘도 무방합니다.
check_char을 통해 지정된 인코딩 단위전략으로 해석이 불가능한 문자를 처리하는 함수를 지정할 수 있습니다. CheckCharFuncType에 대한 자세한 설명은 아래의 참고자료에서 볼 수 있습니다.
참고자료
-
template <typename StrType_>
size_t ReplaceAllStr(StrType_& str, const StrType_& old_str, const StrType_& new_str)
표준 문자열 타입(std::string, std::u16string, std::u32string 등) 객체 str에서 발견되는 모든
old_str을 new_str으로 바꾸고, 바꾼 횟수를 반환합니다. old_str과 new_str의 길이에 따라 최적화된 구현 함수를
호출하여 문자 밀기(또는 당기기)를 최소화 하도록 최적화 되어 있습니다.
-
template <typename EncodingType_, typename StrType_>
StrType_&& StrRotateLeft(
StrType_&& str,
size_t n,
const CheckCharFuncType& check_char = CheckCharFuncType()
)
표준 문자열 타입(std::string, std::u16string, std::u32string 등) 객체 str에서 제일 앞의
(멀티바이트) 문자 n 개를 잘라내서 맨 뒤로 옮긴 후, str 자신을 반환합니다. EncodingType_에 str의
인코딩에 해당하는 인코딩 단위전략을 넘겨줍니다. StrType_이 std::string(1 바이트 문자 타입 기반) 타입이
아닌 경우에는, EncodingType_에 어떤 인코딩 단위전략을 넘겨줘도 무방합니다. n이 str이 포함한 (멀티바이트)
문자 개수보다 크거나 같다면, n을 str이 포함한 (멀티바이트) 문자 개수로 나눈 나머지값(n')에 대해 StrRotateLeft
함수를 적용합니다.
-
template <typename EncodingType_, typename StrType_>
StrType_&& StrRotateRight(
StrType_&& str,
size_t n,
const CheckCharFuncType& check_char = CheckCharFuncType()
)
표준 문자열 타입(std::string, std::u16string, std::u32string 등) 객체 str에서 제일 뒤의
(멀티바이트) 문자 n 개를 잘라내서 맨 앞으로 옮긴 후, str 자신을 반환합니다. EncodingType_에 str의
인코딩에 해당하는 인코딩 단위전략을 넘겨줍니다. StrType_이 std::string(1 바이트 문자 타입 기반) 타입이
아닌 경우에는, EncodingType_에 어떤 인코딩 단위전략을 넘겨줘도 무방합니다. n이 str이 포함한 (멀티바이트)
문자 개수보다 크거나 같다면, n을 str이 포함한 (멀티바이트) 문자 개수로 나눈 나머지값(n')에 대해 StrRotateRight
함수를 적용합니다.
-
template <typename StrType_>
StrType_&& operator <<=(StrType_&& str, size_t n)
표준 문자열 타입(std::string, std::u16string, std::u32string 등) 객체 str에서 제일 앞의
(멀티바이트) 문자 n 개를 잘라내서 맨 뒤로 옮긴 후, str 자신을 반환합니다. StrType_이
std::string(1 바이트 문자 타입 기반) 타입인 경우에는, str이 항상 DefaultEncoding(UTF-8)
으로 인코딩 되어 있어야 합니다. n이 str이 포함한 (멀티바이트) 문자 개수보다 크거나 같다면, n을 str이 포함한
(멀티바이트) 문자 개수로 나눈 나머지값(n')에 대해 <<= 연산자를 적용합니다.
-
template <typename StrType_>
StrType_&& operator >>=(StrType_&& str, size_t n)
표준 문자열 타입(std::string, std::u16string, std::u32string 등) 객체 str에서 제일 뒤의
(멀티바이트) 문자 n 개를 잘라내서 맨 앞으로 옮긴 후, str 자신을 반환합니다. StrType_이
std::string(1 바이트 문자 타입 기반) 타입인 경우에는, str이 항상 DefaultEncoding(UTF-8)
으로 인코딩 되어 있어야 합니다. n이 str이 포함한 (멀티바이트) 문자 개수보다 크거나 같다면, n을 str이 포함한
(멀티바이트) 문자 개수로 나눈 나머지값(n')에 대해 >>= 연산자를 적용합니다.
-
template <typename StrType_>
StrType_ operator <<(const StrType_& str, size_t n)
표준 문자열 타입(std::string, std::u16string, std::u32string 등) 객체 str에서 제일
앞의 (멀티바이트) 문자 n 개를 잘라내서 맨 뒤로 옮긴 문자열(임시 객체)을 만들어 반환합니다. StrType_이
std::string(1 바이트 문자 타입 기반) 타입인 경우에는, str이 항상 DefaultEncoding(UTF-8)
으로 인코딩 되어 있어야 합니다. n 이 str이 포함한 (멀티바이트) 문자 개수보다 크거나 같다면, n을 str이 포함한
(멀티바이트) 문자 개수로 나눈 나머지값(n')에 대해 << 연산자를 적용합니다.
-
template <typename StrType_>
StrType_ operator >>(const StrType_& str, size_t n)
표준 문자열 타입(std::string, std::u16string, std::u32string 등) 객체 str에서 제일
뒤의 (멀티바이트) 문자 n 개를 잘라내서 맨 앞으로 옮긴 문자열(임시 객체)을 만들어 반환합니다. StrType_이
std::string(1 바이트 문자 타입 기반) 타입인 경우에는, str이 항상 DefaultEncoding(UTF-8)
으로 인코딩 되어 있어야 합니다. n 이 str이 포함한 (멀티바이트) 문자 개수보다 크거나 같다면, n을 str이 포함한
(멀티바이트) 문자 개수로 나눈 나머지값(n')에 대해 >> 연산자를 적용합니다.
-
template <typename ResultType_, typename StrType_>
ResultType_ StrToType(const StrType_& str)
표준 문자열 타입(std::string, std::u16string, std::u32string 등) 객체 str을,
템플릿 타입인수로 지정한 ResultType_으로 변환하여 반환합니다. 내부적으로 std::stringstream에
대한 operator >>를 사용하므로, ResultType_에 대한 적절한 operator >>
연산자가 오버로딩 되어 있어야 합니다.
-
template <typename T_>
inline std::string TypeToStr(
const T_& value,
std::function<void(std::stringstream&)> set_format = nullptr
)
T_ 타입 객체 value를 std::string으로 변환하여 반환합니다. 내부적으로 stringstream에 대한
operator <<를 사용하므로, T_에 대한 적절한 operator << 연산자가 오버로딩
되어 있어야 합니다. 두 번째 함수자 set_format을 통해 문자열로 변환할 포맷을 지정할 수 있습니다.
다음은 예제 코드입니다.
- #include
- using namespace blc::ustr;
-
- #include
- using namespace std;
-
- int main()
- {
- cout << TypeToStr(0) << endl;
- cout << TypeToStr(201124478) << endl;
- cout << TypeToStr(0.0) << endl;
- cout << TypeToStr(2011.24478) << endl;
- cout << TypeToStr(24.478) << endl;
- cout << TypeToStr(100'000'000'000'000'000'000.0) << endl;
- cout << TypeToStr(0.000'000'000'000'000'000'01) << endl;
-
-
- auto format1 = [](stringstream& sstream) {
- sstream.width(10);
- sstream.fill('0');
- };
- cout << TypeToStr(10, format1) << endl;
-
- auto format2 = [](stringstream& sstream) {
- sstream << hex;
- };
- cout << TypeToStr(10, format2) << endl;
-
- auto format3 = [](stringstream& sstream) {
- sstream.precision(9);
- };
- cout << TypeToStr(2011.24478, format3) << endl;
-
- auto format4 = [](stringstream& sstream) {
- sstream.precision(6);
- sstream << fixed;
- };
- cout << TypeToStr(34.08, format4) << endl;
-
- return 0;
- }
예제에서는 곧바로 std::cout을 통해 출력했으나, TypeToStr 함수 템플릿의 반환 타입은 모두 std::string입니다.
-
template <...> auto SplitString(...)
문자열을 특정 구분자(또는 구분자들)를 기준으로 자르고 그 자른 문자열 조각을 컨테이너에 담아서 반환하는
함수 템플릿 입니다. 이 함수 템플릿은 두 가지 오버로딩 버전이 제공됩니다.
- template <typename ContainerType_, typename StrType_>
- std::enable_if_t<IsString<std::decay_t<StrType_>>::value, ContainerType_>
- SplitString(const StrType_& str, const StrType_& delimiter, bool allow_empty_str);
-
-
-
-
-
-
- template <typename ResultContainerT_, typename DelimiterContainerT_, typename StrType_>
- std::enable_if_t<IsString<std::decay_t<StrType_>>::value, ResultContainerT_>
- SplitString(
- const StrType_& str,
- const DelimiterContainerT_& delimiters,
- bool allow_empty_str
- );
-
-
-
-