Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
simple_token.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "simple_token.h"
6
7#include <ostream>
8#include <random>
9
10namespace base {
11
12constexpr size_t kRandomTokenLength = 10;
13
14SimpleToken::SimpleToken(const std::string& token) : token_(token) {}
15
16// static
18 const char charset[] =
19 "0123456789"
20 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
21 "abcdefghijklmnopqrstuvwxyz";
22 const size_t max_index = (sizeof(charset) - 1);
23
24 std::string str;
25 for (size_t i = 0; i < kRandomTokenLength; i++) {
26 str.push_back(charset[rand() % max_index]);
27 }
28 return SimpleToken(str);
29}
30
31std::ostream& operator<<(std::ostream& out, const SimpleToken& token) {
32 return out << "(" << token.ToString() << ")";
33}
34
35std::optional<base::SimpleToken> ValueToSimpleToken(std::string str) {
36 return std::make_optional<base::SimpleToken>(str);
37}
38
39std::string SimpleTokenToValue(const SimpleToken& token) {
40 return token.ToString();
41}
42
44 return std::hash<std::string>()(SimpleToken.ToString());
45}
46
47} // namespace base
SimpleToken()=default
std::string ToString() const
static SimpleToken Create()
size_t SimpleTokenHash(const SimpleToken &SimpleToken)
constexpr size_t kRandomTokenLength
std::optional< base::SimpleToken > ValueToSimpleToken(std::string str)
std::string SimpleTokenToValue(const SimpleToken &token)
std::ostream & operator<<(std::ostream &out, const SimpleToken &token)