Vidalia 0.2.10

Local8BitStringValidator.cpp

Go to the documentation of this file.
00001 /*
00002 **  This file is part of Vidalia, and is subject to the license terms in the
00003 **  LICENSE file, found in the top level directory of this distribution. If you
00004 **  did not receive the LICENSE file with this file, you may obtain it from the
00005 **  Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.vidalia-project.net/. No part of Vidalia, including this file,
00007 **  may be copied, modified, propagated, or distributed except according to the
00008 **  terms described in the LICENSE file.
00009 */
00010 
00011 /*
00012 ** \file Local8BitStringValidator.cpp
00013 ** \version $Id: Local8BitStringValidator.cpp 4353 2010-07-14 15:50:50Z edmanm $
00014 ** \brief Validates that a given string contains only characters capable of
00015 ** being represented in the current local 8-bit character encoding.
00016 */
00017 
00018 #include "Local8BitStringValidator.h"
00019 
00020 
00021 /** Constructor. */
00022 Local8BitStringValidator::Local8BitStringValidator(QObject *parent)
00023   : QValidator(parent)
00024 {
00025   _codec = QTextCodec::codecForLocale();
00026 }
00027 
00028 /** Validates the given input contains only valid nickname characters starting
00029  * at the specified position. */
00030 QValidator::State
00031 Local8BitStringValidator::validate(QString &input, int &pos) const
00032 {
00033   Q_UNUSED(pos);
00034 
00035   if (_codec->canEncode(input))
00036     return QValidator::Acceptable;
00037   return QValidator::Invalid;
00038 }
00039 
00040 bool
00041 Local8BitStringValidator::canEncode(const QString &input)
00042 {
00043   return QTextCodec::codecForLocale()->canEncode(input);
00044 }