1 // Copyright (c) 2012 The Chromium 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 "base/guid.h" 6 7 #include <stddef.h> 8 9 #include "base/strings/string_util.h" 10 11 namespace base { 12 IsValidGUID(const std::string & guid)13bool IsValidGUID(const std::string& guid) { 14 const size_t kGUIDLength = 36U; 15 if (guid.length() != kGUIDLength) 16 return false; 17 18 for (size_t i = 0; i < guid.length(); ++i) { 19 char current = guid[i]; 20 if (i == 8 || i == 13 || i == 18 || i == 23) { 21 if (current != '-') 22 return false; 23 } else { 24 if (!IsHexDigit(current)) 25 return false; 26 } 27 } 28 29 return true; 30 } 31 32 } // namespace base 33