void cCmdParser::expandBackslashes (QString &command) { //do nothing if we don't want to expand here if (!expandbackslashes) return; QString cmd = ""; bool backslash = false; int len = command.length(); for (int i = 0; i < len; i++) { QChar ch = command[i]; if (backslash) { if (ch.toLatin1() == 't') //got \t cmd += (QChar) '\t'; else if (ch.toLatin1() == 'e') //got \e cmd += (QChar) '\e'; else if ((ch.toLatin1() == 'm') && (i == 1)) //got \m on the beginning of the string cmd += (QChar) 0x02; else cmd += ch; backslash = false; } else { if (ch == QChar ('\\')) backslash = true; else cmd += command[i]; } }
QList<int> SweetDisplayStandby::getVirtualKey(QKeySequence keySequence) { QList<int> keys; if ( !keySequence.toString().size() ) { return keys; } QString sequenceString = keySequence.toString(); QRegExp rx("\\+"); QStringList query = sequenceString.split(rx); uint modifiers=0; int i = 0, vk =-1; for (; i <query.length()-1; i++ ) { if( query[i] == "Ctrl" ) { modifiers |= MOD_CONTROL; } else if( query[i] == "Alt" ) { modifiers |= MOD_ALT; } else if( query[i] == "Shift" ) { modifiers |= MOD_SHIFT; } else if( query[i] == "Meta" ) { modifiers |= MOD_WIN; } } QString lastKey = query[i]; QRegExp frx ( "^F(\\d+)$"); // F group keys QRegExp drx ( "^(\\d)$"); //digits QRegExp lrx ( "^([A-Z])$"); //capital letters frx.indexIn(lastKey); drx.indexIn(lastKey); lrx.indexIn(lastKey); if (frx.capturedTexts()[1].length()) { vk += VK_F1 + frx.capturedTexts()[1].toInt(); } else if (drx.capturedTexts()[1].length()) { QChar c = drx.capturedTexts()[1][0]; vk = c.toLatin1(); } else if (lrx.capturedTexts()[1].length()) { QChar c = lrx.capturedTexts()[1][0]; vk = c.toLatin1(); } keys.append(modifiers); keys.append(vk); return keys; }
int code128Index(QChar code, int set) { for(int idx = 0; _128codes[idx]._null == false; idx++) { if(set == SETA && _128codes[idx].codea == code.toLatin1()) return idx; if(set == SETB && _128codes[idx].codeb == code.toLatin1()) return idx; if(set == SETC && _128codes[idx].codec == code.toLatin1()) return idx; } return -1; // couldn't find it }
QVariant QJson::parseString(const QString &json, int &index, bool &success, QString *errorMessage) { Q_ASSERT(json[index] == '"'); index++; QString string; QChar ch; while (checkAvailable(json, index, success, errorMessage)) { ch = json[index++]; switch (ch.toLatin1()) { case '\\': // Escaped character if (!checkAvailable(json, index, success, errorMessage)) return QVariant(); ch = json[index++]; switch (ch.toLatin1()) { case 'b': string.append('\b'); break; case 'f': string.append('\f'); break; case 'n': string.append('\n'); break; case 'r': string.append('\r'); break; case 't': string.append('\t'); break; case 'u': if (!checkAvailable(json, index, success, errorMessage, 4)) return QVariant(); string.append(QChar(json.mid(index, 4).toInt(0, 16))); index += 4; break; default: string.append(ch); } break; case '"': // End of string return QVariant(string); default: string.append(ch); } } return QVariant(); }
void Scanner::consumeUntil(const char* stopAt, const char* stopAfter) { QChar ch = m_src.peek(); while (!ch.isNull() && !ch.isSpace() && !std::strchr(stopAt, ch.toLatin1())) { m_src.move(); ch = m_src.peek(); if (stopAfter && !ch.isNull() && std::strchr(stopAfter, ch.toLatin1())) { m_src.move(); break; } } }
static bool parseDate(const QString &str, int &day, int &month, int &year) { day = 0; month = 0; year = 0; int p; for (p = 0; p < (int)(str.length()); p++){ QChar cc = str[p]; char c = cc.toLatin1(); if (c == '_') continue; if ((c < '0') || (c > '9')){ p++; break; } day = day * 10 + (c - '0'); } for (; p < (int)(str.length()); p++){ QChar cc = str[p]; char c = cc.toLatin1(); if (c == '_') continue; if ((c < '0') || (c > '9')){ p++; break; } month = month * 10 + (c - '0'); } for (; p < (int)(str.length()); p++){ QChar cc = str[p]; char c = cc.toLatin1(); if (c == '_') continue; if ((c < '0') || (c > '9')) return false; year = year * 10 + (c - '0'); } if (year < 1000) { /* Year must have 4 digits ! */ year = 0; return true; } if (day && month && year){ QDate d(year, month, day); if (d.isNull()) return false; } return true; }
void SecurityGroup::parseId() { QString p = id(); m_belowLevelGroups.clear(); m_rootName.clear(); while(!p.isEmpty()) { QString pi = p.section(Constants::S_DELIMITER,0,0); if (m_rootName.isEmpty()) { m_rootName = pi; } else { m_belowLevelGroups.append(pi); } p.remove(0, pi.length() + 1); } QString str = id().toLower(); QChar c; m_uniquaId = 0; foreach(c, str) { #if QT_VERSION < 0x050000 m_uniquaId += c.toAscii(); #else m_uniquaId += c.toLatin1(); #endif }
void ChannelHandler::SetChannelUser (const QString& nick, const QString& user, const QString& host) { QString nickName = nick; bool hasRole = false; QChar roleSign; if (CM_->GetISupport ().contains ("PREFIX")) { const QStringList& prefixList = CM_->GetISupport () ["PREFIX"].split (')'); int id = prefixList.value (1).indexOf (nick [0]); if (id != -1) { hasRole = true; nickName = nickName.mid (1); roleSign = prefixList.at (0) [id + 1]; } } CM_->ClosePrivateChat (nickName); const auto existed = Nick2Entry_.contains (nickName); ChannelParticipantEntry_ptr entry (GetParticipantEntry (nickName, false)); entry->SetUserName (user); entry->SetHostName (host); ChannelRole role; if (hasRole) switch (roleSign.toLatin1 ()) { case 'v': role = ChannelRole::Voiced; break; case 'h': role = ChannelRole::HalfOperator; break; case 'o': role = ChannelRole::Operator; break; case 'a': role = ChannelRole::Admin; break; case 'q': role = ChannelRole::Owner; break; default: role = ChannelRole::Participant; } else role = ChannelRole::Participant; entry->SetRole (role); entry->SetStatus (EntryStatus (SOnline, QString ())); if (!existed) CM_->GetAccount ()->handleGotRosterItems ({ entry.get () }); MakeJoinMessage (nickName); }
QValidator::State AddressValidator::validate( QString& string, int& pos ) const { Q_UNUSED( pos ) State result = QValidator::Acceptable; if( mCodecId == ExpressionCoding ) { string = string.trimmed(); if( ! expressionRegex.exactMatch(string) ) result = QValidator::Invalid; //only prefix has been typed: if( string == QStringLiteral("+") || string == QStringLiteral("-") || string.endsWith(QLatin1Char('x')) ) // 0x at end result = QValidator::Intermediate; } else { const int stringLength = string.length(); for( int i=0; i<stringLength; ++i ) { const QChar c = string.at( i ); if( !mValueCodec->isValidDigit( c.toLatin1() ) && !c.isSpace() ) { result = QValidator::Invalid; break; } } } if( string.isEmpty() ) result = QValidator::Intermediate; return result; }
const QString ctkLDAPExpr::ParseState::getAttributeValue() { QString sb; bool exit = false; while( !exit ) { QChar c = peek( ); switch(c.toLatin1()) { case '(': case ')': exit = true; break; case '*': sb.append(WILDCARD); break; case '\\': sb.append(m_str.at(++m_pos)); break; default: sb.append(c); break; } if ( !exit ) { m_pos++; } } return sb; }
QString LinkLocator::highlightedText() { // formating symbols must be prepended with a whitespace if ( ( mPos > 0 ) && !mText[mPos-1].isSpace() ) { return QString(); } const QChar ch = mText[mPos]; if ( ch != '/' && ch != '*' && ch != '_' && ch != '-' ) { return QString(); } QRegExp re = QRegExp( QString( "\\%1((\\w+)([\\s-']\\w+)*( ?[,.:\\?!;])?)\\%2" ).arg( ch ).arg( ch ) ); re.setMinimal( true ); if ( re.indexIn( mText, mPos ) == mPos ) { int length = re.matchedLength(); // there must be a whitespace after the closing formating symbol if ( mPos + length < mText.length() && !mText[mPos + length].isSpace() ) { return QString(); } mPos += length - 1; switch ( ch.toLatin1() ) { case '*': return "<b>*" + re.cap( 1 ) + "*</b>"; case '_': return "<u>_" + re.cap( 1 ) + "_</u>"; case '/': return "<i>/" + re.cap( 1 ) + "/</i>"; case '-': return "<strike>-" + re.cap( 1 ) + "-</strike>"; } } return QString(); }
void IpcMsg::sendMessage(QString msg) { auto shm = new QSharedMemory("TimeTrackShm"); shm->attach(); shm->lock(); // send the message char *to = (char*)shm->data(); QChar *data = msg.data(); while(!data->isNull()){ memset(to, data->toLatin1(), 1); ++data; ++to; } memset(to, 0, 1); shm->unlock(); delete shm; // unlock the listener auto sem = new QSystemSemaphore( "TimeTrackSem", 0, QSystemSemaphore::Open); sem->release(); delete sem; }
QString ScanEdit::textToScanCodes(const QString text) { QString scanCode; for(int i = 0; i < text.length(); i++) { QChar ch = text.at(i).toLatin1(); unsigned char code = 0; if(ch == '\\') { if(i + 1 != text.length()) { QChar next = text.at(i + 1).toLatin1(); if(next == '\\') { i++; } else if(next == 't') { i++; code = TAB; } else if(next == 'n') { i++; code = RETURN; } } } if(code == 0) { code = key2usb[(int)ch.toLatin1()]; } QString hexTxt = YubiKeyUtil::qstrHexEncode(&code, 1); scanCode += hexTxt; } return scanCode; }
inline char to_char(QChar c){ #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) return c.toLatin1(); #else return c.toAscii(); #endif }
static bool isSeparator(const QChar& c) { switch (c.toLatin1()) { case '.': case ',': case '?': case '!': case ':': case ';': case '-': case '<': case '>': case '[': case ']': case '(': case ')': case '{': case '}': case '=': case '/': case '+': case '%': case '&': case '^': case '*': case '\'': case '"': case '~': case '|': return true; default: return false; } }
void winLogReader::read() { if(!m_bOpen) { std::cout << "input file not found" << std::endl; return; } if(!m_bOutOpen) { std::cout << "output file not created" << std::endl; return; } QDataStream inStream(m_file); QTextStream outStream(m_outFile); while(!inStream.atEnd()) { QChar val; inStream >> val; outStream << val.toLatin1(); outStream << "\n"; } }
QStringList Helper::loadTextFile(QSharedPointer<QFile> file, bool trim_lines, QChar skip_header_char, bool skip_empty_lines) { QStringList output; while (!file->atEnd()) { QByteArray line = file->readLine(); //remove newline or trim if (trim_lines) { line = line.trimmed(); } else { while (line.endsWith('\n') || line.endsWith('\r')) line.chop(1); } //skip empty lines if (skip_empty_lines && line.count()==0) continue; //skip header lines if (skip_header_char!=QChar::Null && line.count()!=0 && line[0]==skip_header_char.toLatin1()) continue; output.append(line); } return output; }
void CC708Window::AddChar(QChar ch) { if (!GetExists()) return; QString dbg_char = ch; if (ch.toLatin1() < 32) dbg_char = QString("0x%1").arg( (int)ch.toLatin1(), 0,16); if (!IsPenValid()) { LOG(VB_VBI, LOG_DEBUG, QString("AddChar(%1) at (c %2, r %3) INVALID win(%4,%5)") .arg(dbg_char).arg(pen.column).arg(pen.row) .arg(true_column_count).arg(true_row_count)); return; } if (ch.toLatin1() == 0x0D) { Scroll(pen.row + 1, 0); SetChanged(); return; } QMutexLocker locker(&lock); if (ch.toLatin1() == 0x08) { DecrPenLocation(); CC708Character& chr = GetCCChar(); chr.attr = pen.attr; chr.character = QChar(' '); SetChanged(); return; } CC708Character& chr = GetCCChar(); chr.attr = pen.attr; chr.character = ch; int c = pen.column; int r = pen.row; IncrPenLocation(); SetChanged(); LOG(VB_VBI, LOG_DEBUG, QString("AddChar(%1) at (c %2, r %3) -> (%4,%5)") .arg(dbg_char).arg(c).arg(r).arg(pen.column).arg(pen.row)); }
void MainWindow::cryptText(void) { // If crypt action is toggled, no need to crypt if (m_cryptAction->isChecked()) return; // Get text QString text = m_textEdit->toPlainText(); // If text has a new symbol, try to crypt it if (m_symbolesCount == text.size()-1) { // Get current text cursor position int cursorPosition = m_textEdit->textCursor().position(); // Compute current letter position int letterPosition = cursorPosition-1; // If text is not empty, crypt entered letter if any if (!text.isEmpty()) { // Get the new char QChar oldCurrLetter = text.at(letterPosition); QChar newCurrLetter; // Crypt the lower letter if any if (m_lowerRegExp.exactMatch(oldCurrLetter)) newCurrLetter = QChar((oldCurrLetter.toLatin1()-97 + 1)%(26)+97); // Crypt the upper letter if any if (m_upperRegExp.exactMatch(oldCurrLetter)) newCurrLetter = QChar((oldCurrLetter.toLatin1()-65 + 1)%(26)+65); // If the new char was a letter (upper or lower), crypt it if (!newCurrLetter.isNull()) { // Replace the current letter by the crypted one text.replace(letterPosition, 1, newCurrLetter); // Set text to apply letter change disconnect(m_textEdit, SIGNAL(textChanged(void)), this, SLOT(cryptText(void))); m_textEdit->clear(); m_textEdit->appendPlainText(text); connect(m_textEdit, SIGNAL(textChanged(void)), this, SLOT(cryptText(void))); // Move cursor at right position QTextCursor newTextCursor(m_textEdit->textCursor()); newTextCursor.setPosition(cursorPosition); m_textEdit->setTextCursor(newTextCursor); }
int codeIndex(QChar code) { // we are a case insensitive search code = code.toUpper(); for(int idx = 0; _3of9codes[idx].code != '\0'; idx++) { if(_3of9codes[idx].code == code.toLatin1()) return idx; } return -1; // couldn't find it }
QString convertTo3of9P(QChar c) { const char code = c.toLatin1(); for (int i = 0; !ext3of9map[i].conversion.isEmpty(); i++) if (ext3of9map[i].code == code) return ext3of9map[i].conversion; return QString(); }
bool isDegit(QChar c) { for(int i=0;i<uint_vc_len;i++) { if(c.toLatin1()==uint_vc[i]) return true; } return false; }
static int unpackMPCNumber(QChar ch) //////////////////////////////////// { char c = ch.toLatin1(); if (ch.isDigit()) return(c - '0'); return(10 + c - 'A'); }
void PatternFormatter::createConverter(const QChar &rChar, const FormattingInfo &rFormattingInfo, const QString &rOption) { Q_ASSERT_X(mConversionCharacters.indexOf(rChar) >= 0, "PatternFormatter::createConverter", "Unknown conversion character" ); LogError e("Creating Converter for character '%1' min %2, max %3, left %4 and option '%5'"); e << QString(rChar) << FormattingInfo::intToString(rFormattingInfo.mMinLength) << FormattingInfo::intToString(rFormattingInfo.mMaxLength) << rFormattingInfo.mLeftAligned << rOption; logger()->trace(e); switch (rChar.toLatin1()) { case 'c': mPatternConverters << new LoggerPatternConverter(rFormattingInfo, parseIntegerOption(rOption)); break; case 'd': { QString option = rOption; if (rOption.isEmpty()) option = QLatin1String("ISO8601"); mPatternConverters << new DatePatternConverter(rFormattingInfo, option); break; } case 'm': mPatternConverters << new BasicPatternConverter(rFormattingInfo, BasicPatternConverter::MESSAGE_CONVERTER); break; case 'p': mPatternConverters << new BasicPatternConverter(rFormattingInfo, BasicPatternConverter::LEVEL_CONVERTER); break; case 'r': mPatternConverters << new DatePatternConverter(rFormattingInfo, QLatin1String("TIME_RELATIVE")); break; case 't': mPatternConverters << new BasicPatternConverter(rFormattingInfo, BasicPatternConverter::THREAD_CONVERTER); break; case 'x': mPatternConverters << new BasicPatternConverter(rFormattingInfo, BasicPatternConverter::NDC_CONVERTER); break; case 'X': mPatternConverters << new MDCPatternConverter(rFormattingInfo, rOption); break; default: Q_ASSERT_X(false, "PatternFormatter::createConverter", "Unknown pattern character"); } }
static bool has_path_seperator(const QString& s) { for (int i = 0, len = s.length(); i < len; ++i) { const QChar c = s.at(i); if (Path::is_path_separator(c.toLatin1())) return true; } return false; }
void testTypingValue(QLineEdit *ledit, QPushButton *okButton, const QString &value) { ledit->selectAll(); for (int i = 0; i < value.size(); ++i) { const QChar valChar = value[i]; _keyClick(ledit, valChar.toLatin1()); // ### always guaranteed to work? QVERIFY(ledit->hasAcceptableInput()); QVERIFY(okButton->isEnabled()); } }
int mail_displayer::hex_code_qp(QChar c1, QChar c2) { int n = 0; if (c1>='0' && c1<='9') n = c1.toLatin1()-'0'; else if (c1>='A' && c1<='F') n = c1.toLatin1()-'A'+10; else return -1; if (c2>='0' && c2<='9') n = (n*16) + c2.toLatin1()-'0'; else if (c2>='A' && c2<='F') n = (n*16) + (c2.toLatin1()-'A')+10; else return -1; return n; }
int code128Index(QChar code, int set) { const char latin1Code = code.toLatin1(); for (int idx = 0; _128codes[idx]._null == false; ++idx) { if (set == SETA && _128codes[idx].codea == latin1Code) return idx; if (set == SETB && _128codes[idx].codeb == latin1Code) return idx; if (set == SETC && _128codes[idx].codec == latin1Code) return idx; } return -1; // couldn't find it }
bool game::compareLettersToUsedLetters(QChar selectedLetter) { int value=selectedLetter.toLatin1()-97; if(getUsedLetters(value)==1){ return true; } else{ return false; } }
QStringList QDropboxJson::getArray(QString key, bool force) { QStringList list; if(!valueMap.contains(key)) return list; qdropboxjson_entry e; e = valueMap.value(key); if(!force && e.type != QDROPBOXJSON_TYPE_ARRAY) return list; QString arrayStr = e.value.value->mid(1, e.value.value->length()-2); QString buffer = ""; bool inString = false; int inJson = 0; for(int i=0; i<arrayStr.size(); ++i) { QChar c = arrayStr.at(i); if( ((c != ',' && c != ' ') || inString || inJson) && (c != '"' || inJson > 0)) buffer += c; switch(c.toLatin1()) { case '"': if(i > 0 && arrayStr.at(i-1).toLatin1() == '\\') { buffer += c; break; } else inString = !inString; break; case '{': inJson++; break; case '}': inJson--; break; case ',': if(inJson == 0 && !inString) { list.append(buffer); buffer = ""; } break; } } if(!buffer.isEmpty()) list.append(buffer); return list; }