microsoft/onnxruntime-extensions

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
rel-0.4

Branches

Tags

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

Clone

HTTPS

Download ZIP

operators/string_utils.h

70lines · 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>
0ceb0398Wenbing Li4 years ago7#include "ocos.h"
c891e5d7Wenbing Li5 years ago8
9template <typename T>
10inline void MakeStringInternal(std::ostringstream& ss, const T& t) noexcept {
11ss << t;
12}
13
14template <>
15inline void MakeStringInternal(std::ostringstream& ss, const std::vector<int64_t>& t) noexcept {
16ss << "[";
17for (int i = 0; i < t.size(); i++) {
18if (i != 0) {
19ss << ", ";
20}
21ss << t[i];
22}
23ss << "]";
24}
25
0ceb0398Wenbing Li4 years ago26template <>
27inline void MakeStringInternal(std::ostringstream& ss, const OrtTensorDimensions& t) noexcept {
28MakeStringInternal(ss, static_cast<const std::vector<int64_t>&>(t));
29}
30
c891e5d7Wenbing Li5 years ago31template <>
32inline void MakeStringInternal(std::ostringstream& ss, const std::vector<std::string>& t) noexcept {
33ss << "[";
34for (int i = 0; i < t.size(); i++) {
35if (i != 0) {
36ss << ", ";
37}
38ss << t[i];
39}
40ss << "]";
41}
42
43template <typename T, typename... Args>
44void MakeStringInternal(std::ostringstream& ss, const T& t, const Args&... args) noexcept {
45MakeStringInternal(ss, t);
46MakeStringInternal(ss, args...);
47}
48
49template <typename... Args>
50std::string MakeString(const Args&... args) {
51std::ostringstream ss;
52MakeStringInternal(ss, args...);
53return std::string(ss.str());
54}
55
56std::vector<std::string_view> SplitString(const std::string_view& str, const std::string_view& seps, bool remove_empty_entries = false);
57
aef5ef1eMojimi4 years ago58bool IsCJK(char32_t c);
59
60bool IsAccent(char32_t c);
61
62char32_t StripAccent(char32_t c);
c891e5d7Wenbing Li5 years ago63
64uint64_t Hash64(const char* data, size_t n, uint64_t seed);
65
66inline uint64_t Hash64(const char* data, size_t n) {
67return Hash64(data, n, 0xDECAFCAFFE);
68}
69
70uint64_t Hash64Fast(const char* data, size_t n);