summaryrefslogtreecommitdiffstats
path: root/base/value_conversions.cc
blob: f4957a4610c8316245dd1a6df7511417b513f879 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Copyright (c) 2011 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/value_conversions.h"

#include "base/file_path.h"
#include "base/values.h"

namespace base {

// |Value| internally stores strings in UTF-8, so we have to convert from the
// system native code to UTF-8 and back.
StringValue* CreateFilePathValue(const FilePath& in_value) {
  return new StringValue(in_value.AsUTF8Unsafe());
}

bool GetValueAsFilePath(const Value& value, FilePath* file_path) {
  std::string str;
  if (!value.GetAsString(&str))
    return false;
  if (file_path)
    *file_path = FilePath::FromUTF8Unsafe(str);
  return true;
}

}  // namespace base