microsoft/onnxruntime-extensions

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.4.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

operators/string_utils.h

64lines · modeblame

c891e5d7Wenbing Li5 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3#pragma once
4#include <iostream>
5#include <sstream>
6#include <vector>
7
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 << "[";
16for (int i = 0; i < t.size(); i++) {
17if (i != 0) {
18ss << ", ";
19}
20ss << t[i];
21}
22ss << "]";
23}
24
25template <>
26inline void MakeStringInternal(std::ostringstream& ss, const std::vector<std::string>& t) noexcept {
27ss << "[";
28for (int i = 0; i < t.size(); i++) {
29if (i != 0) {
30ss << ", ";
31}
32ss << t[i];
33}
34ss << "]";
35}
36
37template <typename T, typename... Args>
38void MakeStringInternal(std::ostringstream& ss, const T& t, const Args&... args) noexcept {
39MakeStringInternal(ss, t);
40MakeStringInternal(ss, args...);
41}
42
43template <typename... Args>
44std::string MakeString(const Args&... args) {
45std::ostringstream ss;
46MakeStringInternal(ss, args...);
47return std::string(ss.str());
48}
49
50std::vector<std::string_view> SplitString(const std::string_view& str, const std::string_view& seps, bool remove_empty_entries = false);
51
aef5ef1eMojimi4 years ago52bool IsCJK(char32_t c);
53
54bool IsAccent(char32_t c);
55
56char32_t StripAccent(char32_t c);
c891e5d7Wenbing Li5 years ago57
58uint64_t Hash64(const char* data, size_t n, uint64_t seed);
59
60inline uint64_t Hash64(const char* data, size_t n) {
61return Hash64(data, n, 0xDECAFCAFFE);
62}
63
64uint64_t Hash64Fast(const char* data, size_t n);