diff options
Diffstat (limited to 'base/guid.cc')
| -rw-r--r-- | base/guid.cc | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/base/guid.cc b/base/guid.cc new file mode 100644 index 0000000..920dae5 --- /dev/null +++ b/base/guid.cc @@ -0,0 +1,32 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/guid.h" + +#include "base/rand_util.h" +#include "base/stringprintf.h" + +namespace base { + +bool IsValidGUID(const std::string& guid) { + const size_t kGUIDLength = 36U; + if (guid.length() != kGUIDLength) + return false; + + std::string hexchars = "0123456789ABCDEF"; + for (uint32 i = 0; i < guid.length(); ++i) { + char current = guid[i]; + if (i == 8 || i == 13 || i == 18 || i == 23) { + if (current != '-') + return false; + } else { + if (hexchars.find(current) == std::string::npos) + return false; + } + } + + return true; +} + +} // namespace guid |
