2010-05-28 09:40:21 +02:00
|
|
|
// Copyright (c) 2010, Amar Takhar <verm@aegisub.org>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file charset.h
|
|
|
|
/// @brief Character set detection and manipulation utilities.
|
|
|
|
/// @ingroup libaegisub
|
|
|
|
|
|
|
|
#ifndef LAGI_PRE
|
2010-06-17 02:23:44 +02:00
|
|
|
#include <fstream>
|
|
|
|
#include <functional>
|
2010-05-28 09:40:21 +02:00
|
|
|
#include <map>
|
2010-06-17 02:23:44 +02:00
|
|
|
#include <string>
|
|
|
|
#endif
|
2010-05-28 09:40:21 +02:00
|
|
|
#include <libaegisub/exception.h>
|
|
|
|
|
|
|
|
namespace agi {
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
/// Character set conversion and detection.
|
2010-05-28 09:40:21 +02:00
|
|
|
namespace charset {
|
|
|
|
|
|
|
|
DEFINE_BASE_EXCEPTION_NOINNER(CharsetError, agi::Exception)
|
|
|
|
DEFINE_SIMPLE_EXCEPTION_NOINNER(UnknownCharset, CharsetError, "charset/unknown")
|
|
|
|
|
|
|
|
/// List of detected encodings.
|
|
|
|
typedef std::map<float, std::string, std::greater_equal<float> > CharsetListDetected;
|
|
|
|
|
2011-11-04 20:42:21 +01:00
|
|
|
/// @brief Return a complete list of detected character sets ordered by precedence.
|
2010-05-28 09:40:21 +02:00
|
|
|
/// @param file File to check
|
2010-06-17 02:23:44 +02:00
|
|
|
/// @param[out] list Map to load detected list into.
|
2011-11-04 20:42:21 +01:00
|
|
|
void DetectAll(const std::string &file, CharsetListDetected &list);
|
2010-05-28 09:40:21 +02:00
|
|
|
|
|
|
|
/// @brief Returns the character set with the highest confidence
|
|
|
|
/// @param file File to check
|
|
|
|
/// @return Detected character set.
|
2010-06-17 02:23:44 +02:00
|
|
|
std::string Detect(const std::string &file);
|
2010-05-28 09:40:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace util
|
|
|
|
} // namespace agi
|