guid.cc 715 Bytes
Newer Older
gejun's avatar
gejun committed
1 2 3 4
// 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.

5
#include "butil/guid.h"
gejun's avatar
gejun committed
6

7
namespace butil {
gejun's avatar
gejun committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

bool IsValidGUID(const std::string& guid) {
  const size_t kGUIDLength = 36U;
  if (guid.length() != kGUIDLength)
    return false;

  const std::string hexchars = "0123456789ABCDEF";
  for (uint32_t 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;
}

29
}  // namespace butil