microsoft/onnxruntime-extensions

Public

mirrored from https://github.com/microsoft/onnxruntime-extensionsAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.7.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

base/string_utils.h

77lines · modeblame

c891e5d7Wenbing Li5 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3#pragma once
4#include <sstream>
5#include <vector>
70aa18e1Wenbing Li4 years ago6#include "ocos.h"
c891e5d7Wenbing Li5 years ago7
8template <typename T>
9inline void MakeStringInternal(std::ostringstream& ss, const T& t) noexcept {
10ss << t;
11}
12
13template <>
14inline void MakeStringInternal(std::ostringstream& ss, const std::vector<int64_t>& t) noexcept {
15ss << "[";
7fc02244Wenbing Li3 years ago16for (size_t i = 0; i < t.size(); i++) {
c891e5d7Wenbing Li5 years ago17if (i != 0) {
18ss << ", ";
19}
20ss << t[i];
21}
22ss << "]";
23}
24
70aa18e1Wenbing Li4 years ago25template <>
26inline void MakeStringInternal(std::ostringstream& ss, const OrtTensorDimensions& t) noexcept {
27MakeStringInternal(ss, static_cast<const std::vector<int64_t>&>(t));
28}
29
c891e5d7Wenbing Li5 years ago30template <>
31inline void MakeStringInternal(std::ostringstream& ss, const std::vector<std::string>& t) noexcept {
32ss << "[";
7fc02244Wenbing Li3 years ago33for (size_t i = 0; i < t.size(); i++) {
c891e5d7Wenbing Li5 years ago34if (i != 0) {
35ss << ", ";
36}
37ss << t[i];
38}
39ss << "]";
40}
41
42template <typename T, typename... Args>
43void MakeStringInternal(std::ostringstream& ss, const T& t, const Args&... args) noexcept {
44MakeStringInternal(ss, t);
45MakeStringInternal(ss, args...);
46}
47
48template <typename... Args>
49std::string MakeString(const Args&... args) {
50std::ostringstream ss;
51MakeStringInternal(ss, args...);
52return 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
aef5ef1eMojimi4 years ago57bool IsCJK(char32_t c);
58
59bool IsAccent(char32_t c);
60
44851853Mojimi4 years ago61bool IsSpace(char32_t c);
62
63bool IsPunct(char32_t c);
64
65bool IsControl(char32_t c);
66
46d096f1Mojimi4 years ago67char32_t ToLower(char32_t c);
68
aef5ef1eMojimi4 years ago69char32_t StripAccent(char32_t c);
c891e5d7Wenbing Li5 years ago70
71uint64_t Hash64(const char* data, size_t n, uint64_t seed);
72
73inline uint64_t Hash64(const char* data, size_t n) {
74return Hash64(data, n, 0xDECAFCAFFE);
75}
76
77uint64_t Hash64Fast(const char* data, size_t n);