diff options
Diffstat (limited to 'chrome/browser/parsers/metadata_parser_filebase.cc')
-rw-r--r-- | chrome/browser/parsers/metadata_parser_filebase.cc | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/chrome/browser/parsers/metadata_parser_filebase.cc b/chrome/browser/parsers/metadata_parser_filebase.cc new file mode 100644 index 0000000..2d515c6 --- /dev/null +++ b/chrome/browser/parsers/metadata_parser_filebase.cc @@ -0,0 +1,74 @@ +// Copyright (c) 2009 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 <iostream> +#include <sstream> + +#include "chrome/browser/parsers/metadata_parser_filebase.h" + +#include "base/file_util.h" +#include "base/string_util.h" + +FileMetadataParser::FileMetadataParser(const FilePath& path) + : MetadataParser(path){ + path_ = path; +} + +bool FileMetadataParser::Parse() { + std::string value; + int64 size; + if (file_util::GetFileSize(path_, &size)) { + properties_[MetadataParser::kPropertyFilesize] = Int64ToString(size); + } +#if defined(OS_WIN) + value = WideToUTF8(path_.BaseName().value()); + properties_[MetadataParser::kPropertyTitle] = value; +#elif defined(OS_POSIX) + properties_[MetadataParser::kPropertyTitle] = path_.BaseName().value(); +#endif + return true; +} + +bool FileMetadataParser::GetProperty(const std::string&key, + std::string* value) { + PropertyMap::iterator it = properties_.find(key.c_str()); + if (it == properties_.end()) { + return false; + } + + *value = properties_[key.c_str()]; + return true; +} + +MetadataPropertyIterator* FileMetadataParser::GetPropertyIterator() { + return new FileMetadataPropertyIterator(properties_); +} + +FileMetadataPropertyIterator::FileMetadataPropertyIterator( + PropertyMap& properties): properties_(properties){ + it = properties_.begin(); +} + +bool FileMetadataPropertyIterator::GetNext(std::string* key, + std::string* value) { + if (it == properties_.end()) { + return false; + } + *key = it->first; + *value = it->second; + it++; + return true; +} + +int FileMetadataPropertyIterator::Length() { + return properties_.size(); +} + +bool FileMetadataPropertyIterator::IsEnd() { + if (it == properties_.end()) { + return true; + } else { + return false; + } +} |