microsoft/onnxruntime-extensions

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
9eef22cb81d762f6c093a4740c992582267a783f

Branches

Tags

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

Clone

HTTPS

Download ZIP

operators/string_utils.h

64lines · modecode

1// 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 {
10 ss << t;
11}
12
13template <>
14inline void MakeStringInternal(std::ostringstream& ss, const std::vector<int64_t>& t) noexcept {
15 ss << "[";
16 for (int 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 std::vector<std::string>& t) noexcept {
27 ss << "[";
28 for (int i = 0; i < t.size(); i++) {
29 if (i != 0) {
30 ss << ", ";
31 }
32 ss << t[i];
33 }
34 ss << "]";
35}
36
37template <typename T, typename... Args>
38void MakeStringInternal(std::ostringstream& ss, const T& t, const Args&... args) noexcept {
39 MakeStringInternal(ss, t);
40 MakeStringInternal(ss, args...);
41}
42
43template <typename... Args>
44std::string MakeString(const Args&... args) {
45 std::ostringstream ss;
46 MakeStringInternal(ss, args...);
47 return 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
52bool IsCJK(char32_t c);
53
54bool IsAccent(char32_t c);
55
56char32_t StripAccent(char32_t c);
57
58uint64_t Hash64(const char* data, size_t n, uint64_t seed);
59
60inline uint64_t Hash64(const char* data, size_t n) {
61 return Hash64(data, n, 0xDECAFCAFFE);
62}
63
64uint64_t Hash64Fast(const char* data, size_t n);