microsoft/onnxruntime-extensions

Public

mirrored fromhttps://github.com/microsoft/onnxruntime-extensionsAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
176c1d013864044bcc0747b908bdd32048669401

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

base/string_utils.h

77lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3#pragma once
4#include <sstream>
5#include <vector>
6#include "ort_c_to_cpp.h"
7
8template <typename T>
9inline void MakeStringInternal(std::ostringstream& ss, const T& t) noexcept {
10 ss << t;
11}
12
13template <>
14inline void MakeStringInternal(std::ostringstream& ss, const std::vector<int64_t>& t) noexcept {
15 ss << "[";
16 for (size_t i = 0; i < t.size(); i++) {
17 if (i != 0) {
18 ss << ", ";
19 }
20 ss << t[i];
21 }
22 ss << "]";
23}
24
25template <>
26inline void MakeStringInternal(std::ostringstream& ss, const OrtTensorDimensions& t) noexcept {
27 MakeStringInternal(ss, static_cast<const std::vector<int64_t>&>(t));
28}
29
30template <>
31inline void MakeStringInternal(std::ostringstream& ss, const std::vector<std::string>& t) noexcept {
32 ss << "[";
33 for (size_t i = 0; i < t.size(); i++) {
34 if (i != 0) {
35 ss << ", ";
36 }
37 ss << t[i];
38 }
39 ss << "]";
40}
41
42template <typename T, typename... Args>
43void MakeStringInternal(std::ostringstream& ss, const T& t, const Args&... args) noexcept {
44 MakeStringInternal(ss, t);
45 MakeStringInternal(ss, args...);
46}
47
48template <typename... Args>
49std::string MakeString(const Args&... args) {
50 std::ostringstream ss;
51 MakeStringInternal(ss, args...);
52 return std::string(ss.str());
53}
54
55std::vector<std::string_view> SplitString(const std::string_view& str, const std::string_view& seps, bool remove_empty_entries = false);
56
57bool IsCJK(char32_t c);
58
59bool IsAccent(char32_t c);
60
61bool IsSpace(char32_t c);
62
63bool IsPunct(char32_t c);
64
65bool IsControl(char32_t c);
66
67char32_t ToLower(char32_t c);
68
69char32_t StripAccent(char32_t c);
70
71uint64_t Hash64(const char* data, size_t n, uint64_t seed);
72
73inline uint64_t Hash64(const char* data, size_t n) {
74 return Hash64(data, n, 0xDECAFCAFFE);
75}
76
77uint64_t Hash64Fast(const char* data, size_t n);