Add ICU message format support
[chromium-blink-merge.git] / device / usb / usb_ids.cc
blobfbb5b7ee2ed17deb351642aaab97b83deef8f9c1
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.
5 #include "device/usb/usb_ids.h"
7 #include <stdlib.h>
9 #include "base/basictypes.h"
11 namespace device {
13 namespace {
15 static int CompareVendors(const void* a, const void* b) {
16 const UsbVendor* vendor_a = static_cast<const UsbVendor*>(a);
17 const UsbVendor* vendor_b = static_cast<const UsbVendor*>(b);
18 return vendor_a->id - vendor_b->id;
21 static int CompareProducts(const void* a, const void* b) {
22 const UsbProduct* product_a = static_cast<const UsbProduct*>(a);
23 const UsbProduct* product_b = static_cast<const UsbProduct*>(b);
24 return product_a->id - product_b->id;
27 } // namespace
29 const UsbVendor* UsbIds::FindVendor(uint16_t vendor_id) {
30 const UsbVendor key = {vendor_id, NULL, 0, NULL};
31 void* result = bsearch(&key, vendors_, vendor_size_, sizeof(vendors_[0]),
32 &CompareVendors);
33 if (!result)
34 return NULL;
35 return static_cast<const UsbVendor*>(result);
38 const char* UsbIds::GetVendorName(uint16_t vendor_id) {
39 const UsbVendor* vendor = FindVendor(vendor_id);
40 if (!vendor)
41 return NULL;
42 return vendor->name;
45 const char* UsbIds::GetProductName(uint16_t vendor_id, uint16_t product_id) {
46 const UsbVendor* vendor = FindVendor(vendor_id);
47 if (!vendor)
48 return NULL;
50 const UsbProduct key = {product_id, NULL};
51 void* result = bsearch(&key, vendor->products, vendor->product_size,
52 sizeof(vendor->products[0]), &CompareProducts);
53 if (!result)
54 return NULL;
55 return static_cast<const UsbProduct*>(result)->name;
58 } // namespace device