本文整理汇总了C++中QChar::isPunct方法的典型用法代码示例。如果您正苦于以下问题:C++ QChar::isPunct方法的具体用法?C++ QChar::isPunct怎么用?C++ QChar::isPunct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QChar
的用法示例。
在下文中一共展示了QChar::isPunct方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: eventFilter
bool InputWidget::eventFilter(QObject *watched, QEvent *event)
{
if (event->type() != QEvent::KeyPress)
return false;
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
// keys from BufferView should be sent to (and focus) the input line
BufferView *view = qobject_cast<BufferView *>(watched);
if (view) {
if (keyEvent->text().length() == 1 && !(keyEvent->modifiers() & (Qt::ControlModifier ^ Qt::AltModifier))) { // normal key press
QChar c = keyEvent->text().at(0);
if (c.isLetterOrNumber() || c.isSpace() || c.isPunct() || c.isSymbol()) {
setFocus();
QCoreApplication::sendEvent(inputLine(), keyEvent);
return true;
}
}
return false;
}
else if (watched == ui.inputEdit) {
if (keyEvent->matches(QKeySequence::Find)) {
QAction *act = GraphicalUi::actionCollection()->action("ToggleSearchBar");
if (act) {
act->toggle();
return true;
}
}
return false;
}
return false;
}
示例2: preProcessWrap
QString KStringHandler::preProcessWrap(const QString &text)
{
const QChar zwsp(0x200b);
QString result;
result.reserve(text.length());
for (int i = 0; i < text.length(); i++) {
const QChar c = text[i];
bool openingParens = (c == QLatin1Char('(') || c == QLatin1Char('{') || c == QLatin1Char('['));
bool singleQuote = (c == QLatin1Char('\'') );
bool closingParens = (c == QLatin1Char(')') || c == QLatin1Char('}') || c == QLatin1Char(']'));
bool breakAfter = (closingParens || c.isPunct() || c.isSymbol());
bool nextIsSpace = (i == (text.length() - 1) || text[i + 1].isSpace());
bool prevIsSpace = (i == 0 || text[i - 1].isSpace() || result[result.length() - 1] == zwsp);
// Provide a breaking opportunity before opening parenthesis
if (openingParens && !prevIsSpace)
result += zwsp;
// Provide a word joiner before the single quote
if (singleQuote && !prevIsSpace)
result += QChar(0x2060);
result += c;
if (breakAfter && !openingParens && !nextIsSpace && !singleQuote)
result += zwsp;
}
return result;
}
示例3: cleanWord
/*
* Removes bad characters
*/
QString InstrumentData::cleanWord(QString data)
{
QString out;
QChar c;
for(auto i = data.begin(); i != data.end(); ++i){
c = *i;
if(c.isLetterOrNumber()||c.isPunct()) out.append(c);
}
return out;
}
示例4: readOperator
FormatToken Scanner::readOperator()
{
QString const EXCLUDED_CHARS = QLatin1String("\"'_");
QChar ch = m_src.peek();
while(ch.isPunct() && !EXCLUDED_CHARS.contains(ch)) {
if(ch == QLatin1Char('-') && m_src.peek(1) == QLatin1Char('-'))
break;
m_src.move();
ch = m_src.peek();
}
return FormatToken(Format_Operator, m_src.anchor(), m_src.length());
}
示例5: isBegEndChar
bool QNickValidator::isBegEndChar(QChar ch) const
{
return ch.isLetterOrNumber() || ch.isPunct();
}
示例6: tag
char Filters::BT_ThMLHTML::processText(sword::SWBuf& buf, const sword::SWKey* key, const sword::SWModule* module) {
sword::ThMLHTML::processText(buf, key, module);
CSwordModuleInfo* m = CPointers::backend()->findModuleByName( module->Name() );
if (m && !(m->has(CSwordModuleInfo::lemmas) || m->has(CSwordModuleInfo::strongNumbers))) { //only parse if the module has strongs or lemmas
return 1;
}
QString result;
QString t = QString::fromUtf8(buf.c_str());
QRegExp tag("([.,;]?<sync[^>]+(type|value)=\"([^\"]+)\"[^>]+(type|value)=\"([^\"]+)\"([^<]*)>)+");
QStringList list;
int lastMatchEnd = 0;
int pos = tag.indexIn(t,0);
if (pos == -1) { //no strong or morph code found in this text
return 1; //WARNING: Return alread here
}
while (pos != -1) {
list.append(t.mid(lastMatchEnd, pos+tag.matchedLength()-lastMatchEnd));
lastMatchEnd = pos+tag.matchedLength();
pos = tag.indexIn(t,pos+tag.matchedLength());
}
if (!t.right(t.length() - lastMatchEnd).isEmpty()) {
list.append(t.right(t.length() - lastMatchEnd));
}
tag = QRegExp("<sync[^>]+(type|value|class)=\"([^\"]+)\"[^>]+(type|value|class)=\"([^\"]+)\"[^>]+((type|value|class)=\"([^\"]+)\")*([^<]*)>");
for (QStringList::iterator it = list.begin(); it != list.end(); ++it) {
QString e( *it );
const bool textPresent = (e.trimmed().remove(QRegExp("[.,;:]")).left(1) != "<");
if (!textPresent) {
continue;
}
bool hasLemmaAttr = false;
bool hasMorphAttr = false;
int pos = tag.indexIn(e, 0);
bool insertedTag = false;
QString value;
QString valueClass;
while (pos != -1) {
bool isMorph = false;
bool isStrongs = false;
value = QString::null;
valueClass = QString::null;
// check 3 attribute/value pairs
for (int i = 1; i < 6; i += 2) {
if (i > 4)
i++;
if (tag.cap(i) == "type") {
isMorph = (tag.cap(i+1) == "morph");
isStrongs = (tag.cap(i+1) == "Strongs");
}
else if (tag.cap(i) == "value") {
value = tag.cap(i+1);
}
else if (tag.cap(i) == "class") {
valueClass = tag.cap(i+1);
}
}
// prepend the class qualifier to the value
if (!valueClass.isEmpty()) {
value = valueClass + ":" + value;
// value.append(":").append(value);
}
if (value.isEmpty()) {
break;
}
//insert the span
if (!insertedTag) {
e.replace(pos, tag.matchedLength(), "</span>");
pos += 7;
QString rep = QString("<span lemma=\"").append(value).append("\">");
int startPos = 0;
QChar c = e[startPos];
while ((startPos < pos) && (c.isSpace() || c.isPunct())) {
++startPos;
c = e[startPos];
}
//.........这里部分代码省略.........
示例7: ParseFile
/*
* Ascii: 1 byte
* GBK: 2 byte, with the first byte having a value higher than 127
* UTF-16: 2 byte
* UTF-16-Big-Endian: 2 byte, big endian version of utf-16
* UTF-8: 1 to 6 bytes
*/
int TxtParser::ParseFile(QString filename, QString metafilename, int charPerLine, int linePerPage)
{
std::string fname = filename.toLocal8Bit().toStdString();
std::string metaname = metafilename.toLocal8Bit().toStdString();
MyIfstream sourceFile(fname.c_str());
if(!sourceFile.is_open()){
return 0;
}
std::ofstream metaFile(metaname.c_str(), std::fstream::out | std::fstream::trunc);
QChar c;
int charPerLineCounter = 0;
int linePerPageCounter = 0;
int lastWordPos = 0;
int pageCounter = 0;
charandint ci;
while(sourceFile.read(&c, 1)){
//std::cout<<"c: "<<QString(c).toStdString()<<" pos: "<<sourceFile.tellg()<<std::endl;
//if '\n', add a new line
if(c == '\n'){
linePerPageCounter ++;
if(linePerPageCounter == linePerPage){
linePerPageCounter = 0;
metaFile.seekp(pageCounter * 4, std::ios_base::beg);
ci.i = sourceFile.tellg();
metaFile.write(ci.c, 4);
pageCounter ++;
//std::cout<<"page"<<pageCounter<<" ok(\\n) offset: "<<ci.i<<std::endl;
}
}
//if c is ' ', update the position of the last word we met
else if(c.isSpace()){
lastWordPos = sourceFile.tellg();
charPerLineCounter ++;
if(charPerLineCounter == charPerLine){
charPerLineCounter = 0;
linePerPageCounter ++;
}
if(linePerPageCounter == linePerPage){
linePerPageCounter = 0;
metaFile.seekp(pageCounter * 4, std::ios_base::beg);
ci.i = sourceFile.tellg();
metaFile.write(ci.c, 4);
pageCounter ++;
//std::cout<<"page"<<pageCounter<<" ok(' ') offset: "<<ci.i<<std::endl;
}
}
else if(c.isPunct()){
//if a punctuation is the front of a line, the last word in the last line should be moved to the current line
if(charPerLineCounter == 0){
//if cross pages, change the position of last page
if(linePerPageCounter == 0){
metaFile.seekp(pageCounter * 4 - 4, std::ios_base::beg);
ci.i = lastWordPos;
metaFile.write(ci.c, 4);
charPerLineCounter += sourceFile.tellg() - lastWordPos;
}
else {
charPerLineCounter += sourceFile.tellg() - lastWordPos;
}
if(c != '-')
lastWordPos = sourceFile.tellg();
}
else{
charPerLineCounter ++;
if(charPerLineCounter == charPerLine){
charPerLineCounter = 0;
linePerPageCounter ++;
}
if(linePerPageCounter == linePerPage){
linePerPageCounter = 0;
metaFile.seekp(pageCounter * 4, std::ios_base::beg);
ci.i = sourceFile.tellg();
metaFile.write(ci.c, 4);
pageCounter ++;
//std::cout<<"page"<<pageCounter<<" ok('punc') offset: "<<ci.i<<std::endl;
}
}
}
//english word characters
else if(c.isLetter()){
charPerLineCounter ++;
if(charPerLineCounter == charPerLine){
charPerLineCounter = 0;
charPerLineCounter += sourceFile.tellg() - lastWordPos;
linePerPageCounter ++;
}
if(linePerPageCounter == linePerPage){
linePerPageCounter = 0;
metaFile.seekp(pageCounter * 4, std::ios_base::beg);
ci.i = lastWordPos;
metaFile.write(ci.c, 4);
pageCounter ++;
//std::cout<<"page"<<pageCounter<<" ok(other) offset: "<<ci.i<<std::endl;
//.........这里部分代码省略.........
示例8: autoDetectURL
QString Autocorrect::autoDetectURL(const QString &_word) const
{
QString word = _word;
/* this method is ported from lib/kotext/KoAutoFormat.cpp KoAutoFormat::doAutoDetectUrl
* from KOffice 1.x branch */
// kDebug() <<"link:" << word;
char link_type = 0;
int pos = word.indexOf("http://");
int tmp_pos = word.indexOf("https://");
if (tmp_pos < pos && tmp_pos != -1)
pos = tmp_pos;
tmp_pos = word.indexOf("mailto:/");
if ((tmp_pos < pos || pos == -1) && tmp_pos != -1)
pos = tmp_pos;
tmp_pos = word.indexOf("ftp://");
if ((tmp_pos < pos || pos == -1) && tmp_pos != -1)
pos = tmp_pos;
tmp_pos = word.indexOf("ftp.");
if ((tmp_pos < pos || pos == -1) && tmp_pos != -1) {
pos = tmp_pos;
link_type = 3;
}
tmp_pos = word.indexOf("file:/");
if ((tmp_pos < pos || pos == -1) && tmp_pos != -1)
pos = tmp_pos;
tmp_pos = word.indexOf("news:");
if ((tmp_pos < pos || pos == -1) && tmp_pos != -1)
pos = tmp_pos;
tmp_pos = word.indexOf("www.");
if ((tmp_pos < pos || pos == -1) && tmp_pos != -1 && word.indexOf('.', tmp_pos+4) != -1 ) {
pos = tmp_pos;
link_type = 2;
}
tmp_pos = word.indexOf('@');
if (pos == -1 && tmp_pos != -1) {
pos = tmp_pos-1;
QChar c;
while (pos >= 0) {
c = word.at(pos);
if (c.isPunct() && c != '.' && c != '_') break;
else --pos;
}
if (pos == tmp_pos - 1) // not a valid address
pos = -1;
else
++pos;
link_type = 1;
}
if (pos != -1) {
// A URL inside e.g. quotes (like "http://www.koffice.org" with the quotes) shouldn't include the quote in the URL.
while (!word.at(word.length()-1).isLetter() && !word.at(word.length()-1).isDigit() && word.at(word.length()-1) != '/')
word.truncate(word.length() - 1);
word.remove(0, pos);
QString newWord = word;
if (link_type == 1)
newWord = QString("mailto:") + word;
else if (link_type == 2)
newWord = QString("http://") + word;
else if (link_type == 3)
newWord = QString("ftp://") + word;
kDebug() <<"newWord:" << newWord;
return newWord;
}
return QString();
}
示例9: isSentenceSeparator
static inline bool isSentenceSeparator(const QChar &character)
{
return character.isMark() || character.isPunct() || character.category() == QChar::Separator_Paragraph;
}
示例10: isWordSeparator
static inline bool isWordSeparator(const QChar character)
{
return character.isSpace() || character.isMark() || character.isPunct() || character.isSymbol();
}