Flutter Engine
The Flutter Engine
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
Definition: simple_token.h:28
static SimpleToken Create()
Definition: simple_token.cc:17
size_t SimpleTokenHash(const SimpleToken &SimpleToken)
Definition: simple_token.cc:43
constexpr size_t kRandomTokenLength
Definition: simple_token.cc:12
std::optional< base::SimpleToken > ValueToSimpleToken(std::string str)
Definition: simple_token.cc:35
std::string SimpleTokenToValue(const SimpleToken &token)
Definition: simple_token.cc:39
std::ostream & operator<<(std::ostream &out, const SimpleToken &token)
Definition: simple_token.cc:31