示例#1
0
//-----------------------------------------------------------------------------
QString KPIM::quoteNameIfNecessary( const QString &str )
{
  QString quoted = str;

  QRegExp needQuotes(  "[^ 0-9A-Za-z\\x0080-\\xFFFF]" );
  // avoid double quoting
  if ( ( quoted[0] == '"' ) && ( quoted[quoted.length() - 1] == '"' ) ) {
    quoted = "\"" + escapeQuotes( quoted.mid( 1, quoted.length() - 2 ) ) + "\"";
  }
  else if ( quoted.find( needQuotes ) != -1 ) {
    quoted = "\"" + escapeQuotes( quoted ) + "\"";
  }

  return quoted;
}
示例#2
0
void KabcBridge::addresses(QStringList& result) // includes lists
{
  KCursorSaver busy(KBusyPtr::busy()); // loading might take a while

  KABC::AddressBook *addressBook = KABC::StdAddressBook::self( true );
  KABC::AddressBook::ConstIterator it;
  for( it = addressBook->constBegin(); it != addressBook->constEnd(); ++it ) {
    const QStringList emails = (*it).emails();
    QString n = (*it).prefix() + ' ' +
                (*it).givenName() + ' ' +
                (*it).additionalName() + ' ' +
                (*it).familyName() + ' ' +
                (*it).suffix();
    n = n.simplified();

    QRegExp needQuotes("[^ 0-9A-Za-z\\x0080-\\xFFFF]");
    QString endQuote = "\" ";
    QStringList::ConstIterator mit;
    QString addr, email;

    for ( mit = emails.begin(); mit != emails.end(); ++mit ) {
      email = *mit;
      if (!email.isEmpty()) {
        if (n.isEmpty() || (email.contains( '<' ) ))
          addr.clear();
        else { // do we really need quotes around this name ?
          if (n.contains(needQuotes) )
            addr = '"' + n + endQuote;
          else
            addr = n + ' ';
        }

        if (!addr.isEmpty() && !(email.contains( '<' ) )
            && !(email.contains( '>' ) )
            && !(email.contains( ',' ) ))
          addr += '<' + email + '>';
        else
          addr += email;
        addr = addr.trimmed();
        result.append( addr );
      }
    }
  }

  result += addressBook->allDistributionListNames();

  result.sort();
}
示例#3
0
char * System::quote_argument(const char*str)
{
  FUNCTION_TRACE;
  char *out;

  if (str==NULL)
    return NULL;

  if (needQuotes(str))
  {
    out=(char*)MALLOC(strlen(str)+3);
    strcpy(out,"\"");
    strcat(out,str);
    strcat(out,"\"");
    DEBUG3("Quoting argument '%s'->'%s'\n",str,out);
  }
  else
    out=STRDUP(str);
  return out;
}
示例#4
0
bool WEXPORT WFileName::legal() const
{
    if( !isMask() ) {
        _splitpath( *this, _x.drive, _x.dir, _x.fname, _x.ext );
        bool isLong = needQuotes();
        size_t len = strlen( _x.fname );
        if( len > 0 ) {
            for( size_t i = 0; i < len; i++ ) {
                char ch = _x.fname[i];
                if( isLong ) {
                    if( isIllegalChar( ch ) ) {
                        return( false );
                    }
                } else {
                    if( !isalnum( ch ) && !isSpecialChar( ch ) ) {
                        return( false );
                    }
                }
            }
            return( true );
        }
    }
    return( false );
}