void FindBar::on_replace_all_clicked() { auto text = find_entry_->get_text(); auto replacement_text = replace_entry_->get_text(); /* * This is either clever or stupid... * * Basically, we can't just call locate_matches * and then iterate them because replacing the first will invalidate * all the iterators. So we have to call locate_matches after each replacement * until all the matches are gone. But there is an edge case, if we have a case-insensitive * match, and we replace the same text but with different capitalization (e.g. replace * 'cheese' with 'CHEESE') then the number of matches never changes, even when the replacements * happen - so we'd hit an infinte loop. So what we do is we keep track of the number of matches * if the number of matches changes (goes down) then we don't increment i to read the next match * we just keep replacing matches_[0] till they are all gone. If the number of matches doesn't change * then we increment 'i' each time so we eventually replace all the matches even if they are the same * case! Phew!! */ locate_matches(unicode(text.c_str())); uint32_t i = 0; uint32_t last_matches_size = matches_.size(); while(!matches_.empty() && i < matches_.size()) { replace_text(matches_[i].first, matches_[i].second, replacement_text); locate_matches(unicode(text.c_str())); if(matches_.size() == last_matches_size) { ++i; } } }
void RoundButton::Numbers::paint(Painter &p, int x, int y, int outerWidth) { auto digitsCount = _digits.size(); if (!digitsCount) return; auto progress = anim::easeOutCirc(1., _a_ready.current(1.)); auto width = anim::interpolate(_fromWidth, _toWidth, progress); QString singleChar('0'); if (rtl()) x = outerWidth - x - width; x += width - _digits.size() * _digitWidth; auto fromTop = anim::interpolate(0, _st.font->height, progress) * (_growing ? 1 : -1); auto toTop = anim::interpolate(_st.font->height, 0, progress) * (_growing ? -1 : 1); for (auto i = 0; i != digitsCount; ++i) { auto &digit = _digits[i]; auto from = digit.from; auto to = digit.to; if (from.unicode()) { p.setOpacity(1. - progress); singleChar[0] = from; p.drawText(x + (_digitWidth - digit.fromWidth) / 2, y + fromTop + _st.font->ascent, singleChar); } if (to.unicode()) { p.setOpacity(progress); singleChar[0] = to; p.drawText(x + (_digitWidth - digit.toWidth) / 2, y + toTop + _st.font->ascent, singleChar); } x += _digitWidth; } p.setOpacity(1.); }
/* * Given n characters k[0]..k[n-1], find the corresponding rune or return -1 for * failure, or something < -1 if n is too small. In the latter case, the result * is minus the required n. */ long latin1(Rune *k, int n) { struct cvlist *l; int c; char* p; if(k[0] == 'X') if(n>=5) return unicode(k); else return -5; for(l=latintab; l->ld!=0; l++) if(k[0] == l->ld[0]){ if(n == 1) return -2; if(l->ld[1] == 0) c = k[1]; else if(l->ld[1] != k[1]) continue; else if(n == 2) return -3; else c = k[2]; for(p=l->si; *p!=0; p++) if(*p == c) return l->so[p - l->si]; return -1; } return -1; }
unicode strftime(const DateTime& t, const unicode& fmt) { time_t tt = std::chrono::system_clock::to_time_t(t); char buffer[256]; ::strftime(buffer, 256, fmt.encode().c_str(), localtime(&tt)); return unicode(buffer); }
intptr_t event(const ev * e) { intptr_t ret = 1; cveventtype t = evType(e); if (t != CVE_UPDATE) cvReport("got event %s, %p %p", evName(e), evArg0(e), evArg1(e)); switch (t) { #if !defined NPAPI case CVQ_LOGGER: ret = (intptr_t)report; break; #endif case CVQ_NAME: ret = (intptr_t)"test"; break; case CVQ_XPOS: ret = 50; break; case CVQ_YPOS: ret = 50; break; case CVQ_WIDTH: ret = 640; break; case CVQ_HEIGHT: ret = 480; break; case CVE_INIT: init(); break; case CVE_TERM: term(); break; case CVE_GLINIT: glinit(); break; case CVE_DOWN: ret = down(evWhich(e)); break; case CVE_UP: ret = up(evWhich(e)); break; case CVE_UNICODE: unicode(evUnicode(e)); break; case CVE_MOTION: motion(evX(e), evY(e)); break; case CVE_CLOSE: close(); break; case CVE_INVOKE: invoke(evMethod(e)); break; case CVE_RESIZE: resize(evWidth(e), evHeight(e)); break; case CVE_UPDATE: update(); break; default: ret = 0; break; } return ret; }
String TextCodecQt::decode(const char* bytes, size_t length, bool flush, bool /*stopOnError*/, bool& sawError) { // We chop input buffer to smaller buffers to avoid excessive memory consumption // when the input buffer is big. This helps reduce peak memory consumption in // mobile devices where system RAM is limited. #if OS(SYMBIAN) static const int MaxInputChunkSize = 32 * 1024; #else static const int MaxInputChunkSize = 1024 * 1024; #endif const char* buf = bytes; const char* end = buf + length; String unicode(""); // a non-null string is expected while (buf < end) { int size = end - buf; size = qMin(size, MaxInputChunkSize); QString decoded = m_codec->toUnicode(buf, size, &m_state); unicode.append(decoded); buf += size; } sawError = m_state.invalidChars != 0; if (flush) { m_state.flags = QTextCodec::DefaultConversion; m_state.remainingChars = 0; m_state.invalidChars = 0; } return unicode; }
inline static bool hasSpecialChars(const QString &arg, const uchar (&iqm)[16]) { for (auto it = arg.crbegin(), end = arg.crend(); it != end; ++it) { if (isSpecialChar(it->unicode(), iqm)) return true; } return false; }
String StringUtils::toUnicode(const uint8_t* utf8, int32_t length) { if (length == 0) return L""; CharArray unicode(CharArray::newInstance(length)); int32_t result = toUnicode(utf8, length, unicode); return String(unicode.get(), result); }
static std::wstring _to_unicode(const std::string& text) { if(text.empty()) return L""; size_t length = MultiByteToWideChar(CodePage, 0, text.c_str(), (int)text.size(), nullptr, 0); std::wstring unicode(length, L'C'); MultiByteToWideChar(CodePage, 0, text.c_str(), (int)text.size(), &*unicode.begin(), (int)length); return unicode; }
TPtrC DeprecatedString::des() const { if (!dataHandle[0]->_isUnicodeValid) dataHandle[0]->makeUnicode(); TPtrC tstr((const TUint16*)unicode(), length() ); return tstr; }
//static bool Font::SJISTraits::canBreakAfter(std::string::const_iterator& i) { std::string::const_iterator j = i; uint32 u1 = unicode(j); // See: http://www.wesnoth.org/wiki/JapaneseTranslation#Word-Wrapping // and: http://ja.wikipedia.org/wiki/%E7%A6%81%E5%89%87 switch (u1) { case 0xff08: case 0x3014: case 0xff3b: case 0xff5b: case 0x3008: case 0x300a: case 0x300c: case 0x300e: case 0x3010: case 0x2018: case 0x201c: return false; default: break; } uint32 u2 = unicode(j); switch (u2) { case 0x3001: case 0x3002: case 0xff0c: case 0xff0e: case 0xff09: case 0x3015: case 0xff3d: case 0xff5d: case 0x3009: case 0x300b: case 0x300d: case 0x300f: case 0x3011: case 0x2019: case 0x201d: case 0x309d: case 0x309e: case 0x30fd: case 0x30fe: case 0x3005: case 0xff1f: case 0xff01: case 0xff1a: case 0xff1b: case 0x3041: case 0x3043: case 0x3045: case 0x3047: case 0x3049: case 0x3083: case 0x3085: case 0x3087: case 0x308e: case 0x30a1: case 0x30a3: case 0x30a5: case 0x30a7: case 0x30a9: case 0x30e3: case 0x30e5: case 0x30e7: case 0x30ee: case 0x3063: case 0x30f5: case 0x30c3: case 0x30f6: case 0x30fb: case 0x2026: case 0x30fc: return false; default: break; } // Also don't allow breaking between roman characters if (((u1 >= 'A' && u1 <= 'Z') || (u1 >= 'a' && u1 <= 'z')) && ((u2 >= 'A' && u2 <= 'Z') || (u2 >= 'a' && u2 <= 'z'))) { return false; } return true; }
bool SDLInputField::handleKey(SDL_KeyboardEvent e) { if (!m_active) return false; bool pressed=e.state==SDL_PRESSED; SDLKey k(e.keysym.sym); if (!pressed) return true; // check for special keys switch (k) { case SDLK_RETURN: case SDLK_KP2: case SDLK_KP6: case SDLK_RIGHT: case SDLK_DOWN: { input.emit(m_content); printed.emit('\n'); setActive(false); return true; } break; case SDLK_DELETE: case SDLK_BACKSPACE: case SDLK_LEFT: { unsigned s=m_content.size(); if (s) m_content.resize(s-1); printed.emit(k); return true; } break; default: break; } Uint16 unicode(e.keysym.unicode); char ch; if ( (unicode & 0xFF80) == 0 ) { ch = unicode & 0x7F; if (ch>=32) { m_content+=ch; printed.emit(ch); return true; } } else { std::cerr << "An International Character.\n"; } return false; }
std::pair<unicode, int> DocumentView::get_font_name_and_size_from_dconf() { auto settings = Gio::Settings::create("org.gnome.desktop.interface"); auto font_name = settings->get_string("monospace-font-name"); auto parts = unicode(font_name).split(" "); int size = 10; try { //Assume that the last part is the font size, if it's not //then fall back to size 10 and don't alter the font name size = parts.back().to_int(); parts.pop_back(); //FIXME: This is a hack to remove the style from the name... if(parts.back() == "Medium") { parts.pop_back(); } font_name = _u(" ").join(parts).encode(); } catch(std::exception& e) {} return std::make_pair(unicode(std::string(font_name)), size * PANGO_SCALE); }
virtual State validate ( QString & input, int & ) const { if (input.length() == 0) return Intermediate; if (input.length() == 1) return Acceptable; if (input.length() == 2 && input.at(0) == '0' && input.at(1).toLower() == 'x') return Intermediate; if (unicode(input)) return Acceptable; return Invalid; }
int luaM_toucs2(lua_State *L) { const char* value = luaL_checkstring(L, 1); ptrW unicode(mir_utf8decodeW(value)); size_t length = mir_wstrlen(unicode) * sizeof(wchar_t); ptrA string((char*)mir_calloc(length + 1)); memcpy(string, unicode, length); lua_pushlstring(L, string, length + 1); return 1; }
QString PrepareTestValue(const QString ¤t, QChar filler) { auto size = current.size(); auto result = QString(size + 1, filler); auto inCommand = false; for (auto i = 0; i != size; ++i) { auto ch = current[i]; auto newInCommand = (ch.unicode() == TextCommand) ? (!inCommand) : inCommand; if (inCommand || newInCommand || ch.isSpace()) { result[i + 1] = ch; } inCommand = newInCommand; } return result; }
EmojiBlock::EmojiBlock(const style::font &font, const QString &str, uint16 from, uint16 length, uchar flags, uint16 lnkIndex, EmojiPtr emoji) : ITextBlock(font, str, from, length, flags, lnkIndex) , emoji(emoji) { _flags |= ((TextBlockTEmoji & 0x0F) << 8); _width = int(st::emojiSize + 2 * st::emojiPadding); _rpadding = 0; for (auto i = length; i != 0;) { auto ch = str[_from + (--i)]; if (ch.unicode() == QChar::Space) { _rpadding += font->spacew; } else { break; } } }
static char* UnicodeToNative(JSContext *cx, const jschar *source, size_t slen) { nsCAutoString native; nsDependentString unicode(source, slen); nsresult rv = NS_CopyUnicodeToNative(unicode, native); if (NS_FAILED(rv)) { JS_ReportError(cx, "could not convert string to native charset"); return NULL; } char* result = static_cast<char*>(JS_malloc(cx, native.Length() + 1)); if (!result) return NULL; memcpy(result, native.get(), native.Length() + 1); return result; }
void DocumentView::run_linters_and_stuff(bool force) { L_DEBUG("DocumentView::run_linters_and_stuff"); if(!force && window().current_buffer().get() != this) { //Only run linters on the active document L_DEBUG("Document is not active, not running"); return; } L_DEBUG("Detecting language"); apply_language_to_buffer(guess_language_from_file(file_)); L_DEBUG("Applying settings"); apply_settings(guess_mimetype()); //Make sure we update the settings when we've reloaded the file //Check for coverage stats auto language = buffer()->get_language(); unicode name = (language) ? unicode(language->get_name()) : ""; if(name == "Python") { if(!coverage_) { std::cout << "COVERAGE: Creating coverage" << std::endl; coverage_ = std::make_shared<coverage::PythonCoverage>(); //Connect to the coverage updated signal and re-run this function if that happens coverage_->signal_coverage_updated().connect(std::bind(&DocumentView::run_linters_and_stuff, this, false)); } coverage_->apply_to_document(this); linter_ = std::make_shared<linter::PythonLinter>(); linter_->apply_to_document(this); } else if(name == "JavaScript") { linter_ = std::make_shared<linter::JavascriptLinter>(); linter_->apply_to_document(this); } else { if(coverage_) { coverage_->clear_document(this); coverage_.reset(); } if(linter_) { linter_->clear_document(this); linter_.reset(); } } }
// ----------------------------------------------------------------------------- // CMetaDataFieldContainer::At // ----------------------------------------------------------------------------- // EXPORT_C TPtrC CMetaDataFieldContainer::At( TInt aPosition, TMetaDataFieldId& aFieldId ) const { TInt count( iFields.Count() ); if ( count == 0 ) { return KNullDesC(); } if ( aPosition < 0 || aPosition > count ) { return KNullDesC(); } aFieldId = iFields[aPosition]->Id(); if(aFieldId == EMetaDataJpeg) { TPtrC8 pic = iFields[aPosition]->Data8(); TInt length = pic.Length(); if( length ) { if(iD16) { delete iD16; iD16 = NULL; } TRAPD(err, iD16 = HBufC::NewL(length)); if(err != KErrNone) { return KNullDesC(); } i16BitAlbumArt = ETrue; TPtr unicode( iD16->Des() ); unicode.Copy( pic ); return unicode; } } return iFields[aPosition]->Data(); }
void FindBar::on_entry_changed() { last_selected_match_ = -1; auto text = unicode(find_entry_->get_text().c_str()); if(text.empty()) { find_entry_->override_color(default_entry_colour_, Gtk::STATE_FLAG_FOCUSED); toggle_replace(false); return; } std::vector<Gtk::TextBuffer::iterator> iters; int highlighted = highlight_all(text, iters); if(!highlighted) { find_entry_->override_color(Gdk::RGBA("#FF0000"), Gtk::STATE_FLAG_FOCUSED); } else { window_.current_buffer()->view().scroll_to(iters.at(0)); find_entry_->override_color(default_entry_colour_, Gtk::STATE_FLAG_FOCUSED); } toggle_replace(highlighted > 0); }
void FindBar::on_find_next_clicked() { if(!window_.current_buffer()) { return; } auto buf = window_.current_buffer()->buffer(); auto start = buf->get_iter_at_mark(buf->get_insert()); auto text = unicode(find_entry_->get_text().c_str()); locate_matches(text); auto next = find_next_match(start); last_selected_match_ = next; if(next > -1) { auto match = matches_[next]; buf->select_range(match.first, match.second); window_.current_buffer()->view().scroll_to(match.first); } }
// ----------------------------------------------------------------------------- // CMetaDataFieldContainer::Field // ----------------------------------------------------------------------------- // EXPORT_C TPtrC CMetaDataFieldContainer::Field( TMetaDataFieldId aFieldId ) const { TInt count( iFields.Count() ); for ( TInt i = 0; i < count; i++ ) { if ( iFields[i]->Id() == aFieldId ) { if(aFieldId != EMetaDataJpeg) { return iFields[i]->Data(); } else { TPtrC8 pic = iFields[i]->Data8(); TInt length = pic.Length(); if( length ) { if( iD16 ) { delete iD16; iD16 = NULL; } TRAPD(err, iD16 = HBufC::NewL(length)); if (err == KErrNone) { i16BitAlbumArt = ETrue; TPtr unicode( iD16->Des() ); unicode.Copy( pic ); return unicode; } } } } } // Searched field Id wasn't found return KNullDesC(); }
template<> jsval ScriptInterface::ToJSVal<SDL_Event_>(JSContext* cx, SDL_Event_ const& val) { const char* typeName; switch (val.ev.type) { case SDL_ACTIVEEVENT: typeName = "activeevent"; break; case SDL_KEYDOWN: typeName = "keydown"; break; case SDL_KEYUP: typeName = "keyup"; break; case SDL_MOUSEMOTION: typeName = "mousemotion"; break; case SDL_MOUSEBUTTONDOWN: typeName = "mousebuttondown"; break; case SDL_MOUSEBUTTONUP: typeName = "mousebuttonup"; break; case SDL_QUIT: typeName = "quit"; break; case SDL_VIDEOEXPOSE: typeName = "videoexpose"; break; case SDL_VIDEORESIZE: typeName = "videoresize"; break; case SDL_HOTKEYDOWN: typeName = "hotkeydown"; break; case SDL_HOTKEYUP: typeName = "hotkeyup"; break; default: typeName = "(unknown)"; break; } JSObject* obj = JS_NewObject(cx, NULL, NULL, NULL); if (! obj) return JSVAL_VOID; SET(obj, "type", typeName); switch (val.ev.type) { case SDL_ACTIVEEVENT: { SET(obj, "gain", (int)val.ev.active.gain); SET(obj, "state", (int)val.ev.active.state); break; } case SDL_KEYDOWN: case SDL_KEYUP: { // SET(obj, "which", (int)val.ev.key.which); // (not in wsdl.h) // SET(obj, "state", (int)val.ev.key.state); // (not in wsdl.h) JSObject* keysym = JS_NewObject(cx, NULL, NULL, NULL); if (! keysym) return JSVAL_VOID; jsval keysymVal = OBJECT_TO_JSVAL(keysym); JS_SetProperty(cx, obj, "keysym", &keysymVal); // SET(keysym, "scancode", (int)val.ev.key.keysym.scancode); // (not in wsdl.h) SET(keysym, "sym", (int)val.ev.key.keysym.sym); // SET(keysym, "mod", (int)val.ev.key.keysym.mod); // (not in wsdl.h) if (val.ev.key.keysym.unicode) { std::wstring unicode(1, (wchar_t)val.ev.key.keysym.unicode); SET(keysym, "unicode", unicode); } else { SET(keysym, "unicode", CScriptVal(JSVAL_VOID)); } // TODO: scripts have no idea what all the key/mod enum values are; // we should probably expose them as constants if we expect scripts to use them break; } case SDL_MOUSEMOTION: { // SET(obj, "which", (int)val.ev.motion.which); // (not in wsdl.h) // SET(obj, "state", (int)val.ev.motion.state); // (not in wsdl.h) SET(obj, "x", (int)val.ev.motion.x); SET(obj, "y", (int)val.ev.motion.y); // SET(obj, "xrel", (int)val.ev.motion.xrel); // (not in wsdl.h) // SET(obj, "yrel", (int)val.ev.motion.yrel); // (not in wsdl.h) break; } case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: { // SET(obj, "which", (int)val.ev.button.which); // (not in wsdl.h) SET(obj, "button", (int)val.ev.button.button); SET(obj, "state", (int)val.ev.button.state); SET(obj, "x", (int)val.ev.button.x); SET(obj, "y", (int)val.ev.button.y); break; } case SDL_HOTKEYDOWN: case SDL_HOTKEYUP: { SET(obj, "hotkey", static_cast<const char*>(val.ev.user.data1)); break; } } jsval rval = OBJECT_TO_JSVAL(obj); return rval; }
static int getToken() { const char tab[] = "bfnrt\"\'\\"; const char backTab[] = "\b\f\n\r\t\"\'\\"; yyIdent.clear(); yyComment.clear(); yyString.clear(); while ( yyCh != EOF ) { yyLineNo = yyCurLineNo; if ( yyCh.isLetter() || yyCh.toLatin1() == '_' ) { do { yyIdent.append(yyCh); yyCh = getChar(); } while ( yyCh.isLetterOrNumber() || yyCh.toLatin1() == '_' ); if (yyTok != Tok_Dot) { switch ( yyIdent.at(0).toLatin1() ) { case 'r': if ( yyIdent == QLatin1String("return") ) return Tok_return; break; case 'c': if ( yyIdent == QLatin1String("class") ) return Tok_class; break; case 'n': if ( yyIdent == QLatin1String("null") ) return Tok_null; break; } } switch ( yyIdent.at(0).toLatin1() ) { case 'T': // TR() for when all else fails if ( yyIdent == QLatin1String("TR") ) return Tok_tr; break; case 'p': if( yyIdent == QLatin1String("package") ) return Tok_Package; break; case 't': if ( yyIdent == QLatin1String("tr") ) return Tok_tr; if ( yyIdent == QLatin1String("translate") ) return Tok_translate; } return Tok_Ident; } else { switch ( yyCh.toLatin1() ) { case '/': yyCh = getChar(); if ( yyCh == QLatin1Char('/') ) { do { yyCh = getChar(); if (yyCh == EOF) break; yyComment.append(yyCh); } while (yyCh != QLatin1Char('\n')); return Tok_Comment; } else if ( yyCh == QLatin1Char('*') ) { bool metAster = false; bool metAsterSlash = false; while ( !metAsterSlash ) { yyCh = getChar(); if ( yyCh == EOF ) { yyMsg() << qPrintable(LU::tr("Unterminated Java comment.\n")); return Tok_Comment; } yyComment.append( yyCh ); if ( yyCh == QLatin1Char('*') ) metAster = true; else if ( metAster && yyCh == QLatin1Char('/') ) metAsterSlash = true; else metAster = false; } yyComment.chop(2); yyCh = getChar(); return Tok_Comment; } break; case '"': yyCh = getChar(); while ( yyCh != EOF && yyCh != QLatin1Char('\n') && yyCh != QLatin1Char('"') ) { if ( yyCh == QLatin1Char('\\') ) { yyCh = getChar(); if ( yyCh == QLatin1Char('u') ) { yyCh = getChar(); uint unicode(0); for (int i = 4; i > 0; --i) { unicode = unicode << 4; if( yyCh.isDigit() ) { unicode += yyCh.digitValue(); } else { int sub(yyCh.toLower().toLatin1() - 87); if( sub > 15 || sub < 10) { yyMsg() << qPrintable(LU::tr("Invalid Unicode value.\n")); break; } unicode += sub; } yyCh = getChar(); } yyString.append(QChar(unicode)); } else if ( yyCh == QLatin1Char('\n') ) { yyCh = getChar(); } else { yyString.append( QLatin1Char(backTab[strchr( tab, yyCh.toLatin1() ) - tab]) ); yyCh = getChar(); } } else { yyString.append(yyCh); yyCh = getChar(); } } if ( yyCh != QLatin1Char('"') ) yyMsg() << qPrintable(LU::tr("Unterminated string.\n")); yyCh = getChar(); return Tok_String; case ':': yyCh = getChar(); return Tok_Colon; case '\'': yyCh = getChar(); if ( yyCh == QLatin1Char('\\') ) yyCh = getChar(); do { yyCh = getChar(); } while ( yyCh != EOF && yyCh != QLatin1Char('\'') ); yyCh = getChar(); break; case '{': yyCh = getChar(); return Tok_LeftBrace; case '}': yyCh = getChar(); return Tok_RightBrace; case '(': if (yyParenDepth == 0) yyParenLineNo = yyCurLineNo; yyParenDepth++; yyCh = getChar(); return Tok_LeftParen; case ')': if (yyParenDepth == 0) yyParenLineNo = yyCurLineNo; yyParenDepth--; yyCh = getChar(); return Tok_RightParen; case ',': yyCh = getChar(); return Tok_Comma; case '.': yyCh = getChar(); return Tok_Dot; case ';': yyCh = getChar(); return Tok_Semicolon; case '+': yyCh = getChar(); if (yyCh == QLatin1Char('+')) { yyCh = getChar(); return Tok_PlusPlus; } if( yyCh == QLatin1Char('=') ) { yyCh = getChar(); return Tok_PlusEq; } return Tok_Plus; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { QByteArray ba; ba += yyCh.toLatin1(); yyCh = getChar(); bool hex = yyCh == QLatin1Char('x'); if ( hex ) { ba += yyCh.toLatin1(); yyCh = getChar(); } while ( hex ? isxdigit(yyCh.toLatin1()) : yyCh.isDigit() ) { ba += yyCh.toLatin1(); yyCh = getChar(); } bool ok; yyInteger = ba.toLongLong(&ok); if (ok) return Tok_Integer; break; } default: yyCh = getChar(); } } } return Tok_Eof; }
void RegExp::compileMatchOnly(VM* vm, Yarr::YarrCharSize charSize) { ConcurrentJSLocker locker(m_lock); Yarr::YarrPattern pattern(m_patternString, m_flags, &m_constructionError, vm->stackLimit()); if (m_constructionError) { RELEASE_ASSERT_NOT_REACHED(); #if COMPILER_QUIRK(CONSIDERS_UNREACHABLE_CODE) m_state = ParseError; return; #endif } ASSERT(m_numSubpatterns == pattern.m_numSubpatterns); if (!hasCode()) { ASSERT(m_state == NotCompiled); vm->regExpCache()->addToStrongCache(this); m_state = ByteCode; } #if ENABLE(YARR_JIT) if (!pattern.m_containsBackreferences && !pattern.containsUnsignedLengthPattern() && !unicode() && vm->canUseRegExpJIT()) { Yarr::jitCompile(pattern, charSize, vm, m_regExpJITCode, Yarr::MatchOnly); if (!m_regExpJITCode.isFallBack()) { m_state = JITCode; return; } } #else UNUSED_PARAM(charSize); #endif m_state = ByteCode; m_regExpBytecode = Yarr::byteCompile(pattern, &vm->m_regExpAllocator, &vm->m_regExpAllocatorLock); }
// ----------------------------------------------------------------------------- // 3GPExtParser::GetilstBoxesL // ----------------------------------------------------------------------------- // EXPORT_C void C3GPExtParser::GetilstBoxesL(const TDesC8 &/*aBox*/, TMetaDataFieldId aFieldId, HBufC** aBuf) { #ifdef _DEBUG RDebug::Print(_L("C3GPExtParser::GetilstBoxesL")); #endif TUint32 offset = 0; TUint32 size = 0; switch(aFieldId) { case EMetaDataSongTitle: offset = iTitleOffset; size = iTitleSize; break; case EMetaDataArtist: offset = iArtistOffset; size = iArtistSize; break; case EMetaDataAlbum: offset = iAlbumOffset; size = iAlbumSize; break; case EMetaDataComposer: offset = iComposerOffset; size = iComposerSize; break; case EMetaDataComment: offset = iCommentOffset; size = iCommentSize; break; case EMetaDataRating: offset = iCustomGenreOffset; size = iCustomGenreSize; break; case EMetaDataYear: offset = iYearOffset; size = iYearSize; break; case EMetaDataGenre: offset = iGenreOffset; size = iGenreSize; break; case EMetaDataAlbumTrack: offset = iTrackNumberOffset; size = iTrackNumberSize; break; case EMetaDataJpeg: offset = iCoverOffset; size = iCoverSize; break; default: break; } if(size <= 0 || size >= (KMaxTInt/2)) { User::Leave(KErrNotFound); // no data } TInt length = ilst.Length(); if (length < 0 || length < (offset + size)) { User::Leave(KErrNotFound); // no data } // actual data ptr TPtrC8 data = ilst.Mid(offset, size); if(aFieldId != EMetaDataGenre && aFieldId != EMetaDataAlbumTrack && aFieldId != EMetaDataJpeg) { // string meta data *aBuf = HBufC::NewL(size); TPtr data16Ptr( (*aBuf)->Des() ); data16Ptr.Copy(data); } else if(aFieldId == EMetaDataGenre) { // 0x XXXX ID3v1 Genre + 1 TInt16 num = 0; for(TInt i = 0 ; i <= 1; i++) { num <<= 8; num |= data[i]; } num -= 1; // getting it to ID3 if((num >= 0 && num <= 125) || num == 199) { *aBuf = HBufC::NewL(KMaxGenreSize); TPtr genrePtr = (*aBuf)->Des(); MapID3GenreToString(num, genrePtr); } } else if(aFieldId == EMetaDataAlbumTrack) { *aBuf = HBufC::NewL(6); TUint num = 0; for(TInt i = 0 ; i <= 1; i++) { num <<= 8; num |= data[i+2]; } TBuf<6> data16; data16.NumUC(num); (**aBuf) = data16; } else if(aFieldId == EMetaDataJpeg) { TPtrC8 imageMime1 = data.Mid(6, 4); TPtrC8 imageMime2 = data.Mid(1, 3); _LIT8(KJFIF, "JFIF"); _LIT8(KPNG, "PNG"); if(imageMime1.Compare(KJFIF) != 0 && imageMime2.Compare(KPNG) != 0) { // only JPEG and PNG supported User::Leave(KErrNotFound); // no data } if(imageMime1.Compare(KJFIF) == 0) { TPtrC8 pic = data.Mid(0, size); TInt length = pic.Length(); if ( length ) { *aBuf = HBufC::NewL( length ); TPtr unicode( (*aBuf)->Des() ); unicode.Copy( pic ); } } else if(imageMime2.Compare(KPNG) == 0) { TPtrC8 pic = data.Mid(0, size); TInt length = pic.Length(); if ( length ) { *aBuf = HBufC::NewL( length ); TPtr unicode( (*aBuf)->Des() ); unicode.Copy( pic ); } } } }
// ----------------------------------------------------------------------------- // 3GPExtParser::GetilstBoxesL for 8-bit descriptor fields // ----------------------------------------------------------------------------- // EXPORT_C void C3GPExtParser::GetilstBoxesL(const TDesC8 &/*aBox*/, TMetaDataFieldId aFieldId, HBufC8** aBuf) { #ifdef _DEBUG RDebug::Print(_L("C3GPExtParser::GetilstBoxesL 8 bit version")); #endif TUint32 offset = 0; TUint32 size = 0; switch(aFieldId) { case EMetaDataSongTitle: offset = iTitleOffset; size = iTitleSize; break; case EMetaDataArtist: offset = iArtistOffset; size = iArtistSize; break; case EMetaDataAlbum: offset = iAlbumOffset; size = iAlbumSize; break; case EMetaDataComposer: offset = iComposerOffset; size = iComposerSize; break; case EMetaDataComment: offset = iCommentOffset; size = iCommentSize; break; case EMetaDataRating: offset = iCustomGenreOffset; size = iCustomGenreSize; break; case EMetaDataYear: offset = iYearOffset; size = iYearSize; break; case EMetaDataGenre: offset = iGenreOffset; size = iGenreSize; break; case EMetaDataAlbumTrack: offset = iTrackNumberOffset; size = iTrackNumberSize; break; case EMetaDataJpeg: offset = iCoverOffset; size = iCoverSize; break; default: break; } if(size <= 0 || size >= (KMaxTInt/2)) { User::Leave(KErrNotFound); // no data } TInt length = ilst.Length(); if (length < 0 || length < (offset + size)) { User::Leave(KErrNotFound); // no data } // actual data ptr TPtrC8 data = ilst.Mid(offset, size); if(aFieldId != EMetaDataGenre && aFieldId != EMetaDataAlbumTrack && aFieldId != EMetaDataJpeg) { // string meta data *aBuf = HBufC8::NewL(size); TPtr8 unicode( (*aBuf)->Des() ); unicode.Copy(data); } if(aFieldId == EMetaDataJpeg) { TPtrC8 imageMime1 = data.Mid(6, 4); TPtrC8 imageMime2 = data.Mid(1, 3); _LIT8(KJFIF, "JFIF"); _LIT8(KPNG, "PNG"); if(imageMime1.Compare(KJFIF) != 0 && imageMime2.Compare(KPNG) != 0) { // only JPEG and PNG supported User::Leave(KErrNotFound); // no data } if(imageMime1.Compare(KJFIF) == 0) { TPtrC8 pic = data.Mid(0, size); TInt length = pic.Length(); if ( length ) { *aBuf = HBufC8::NewL( length ); TPtr8 unicode( (*aBuf)->Des() ); unicode.Copy( pic ); } } else if(imageMime2.Compare(KPNG) == 0) { TPtrC8 pic = data.Mid(0, size); TInt length = pic.Length(); if ( length ) { *aBuf = HBufC8::NewL( length ); TPtr8 unicode( (*aBuf)->Des() ); unicode.Copy( pic ); } } } }
InlineBotQuery ParseInlineBotQuery(not_null<const Ui::InputField*> field) { auto result = InlineBotQuery(); const auto &text = field->getTextWithTags().text; const auto textLength = text.size(); auto inlineUsernameStart = 1; auto inlineUsernameLength = 0; if (textLength > 2 && text[0] == '@' && text[1].isLetter()) { inlineUsernameLength = 1; for (auto i = inlineUsernameStart + 1; i != textLength; ++i) { const auto ch = text[i]; if (ch.isLetterOrNumber() || ch.unicode() == '_') { ++inlineUsernameLength; continue; } else if (!ch.isSpace()) { inlineUsernameLength = 0; } break; } auto inlineUsernameEnd = inlineUsernameStart + inlineUsernameLength; auto inlineUsernameEqualsText = (inlineUsernameEnd == textLength); auto validInlineUsername = false; if (inlineUsernameEqualsText) { validInlineUsername = text.endsWith(qstr("bot")); } else if (inlineUsernameEnd < textLength && inlineUsernameLength) { validInlineUsername = text[inlineUsernameEnd].isSpace(); } if (validInlineUsername) { auto username = text.midRef(inlineUsernameStart, inlineUsernameLength); if (username != result.username) { result.username = username.toString(); if (const auto peer = App::peerByName(result.username)) { if (const auto user = peer->asUser()) { result.bot = peer->asUser(); } else { result.bot = nullptr; } result.lookingUpBot = false; } else { result.bot = nullptr; result.lookingUpBot = true; } } if (result.lookingUpBot) { result.query = QString(); return result; } else if (result.bot && (!result.bot->botInfo || result.bot->botInfo->inlinePlaceholder.isEmpty())) { result.bot = nullptr; } else { result.query = inlineUsernameEqualsText ? QString() : text.mid(inlineUsernameEnd + 1); return result; } } else { inlineUsernameLength = 0; } } if (inlineUsernameLength < 3) { result.bot = nullptr; result.username = QString(); } result.query = QString(); return result; }
static void Keyaction(Widget w, XEvent *e, String *p, Cardinal *np) { static unsigned char compose[5]; static int composing = -2; int kind = Kraw; int c, len, minmod; KeySym k, mk; Charfunc f; Modifiers md; char buf[100] = {0}; c = 0; len = 0; /* Translate the keycode into a key symbol. */ if(e->xany.type != KeyPress) return; XkbTranslateKeyCode(xkb, (KeyCode)e->xkey.keycode, e->xkey.state, &md, &k); XkbTranslateKeySym(e->xany.display, &k, e->xkey.state, buf, sizeof(buf) - 1, &len); /* Check to see if it's a specially-handled key first. */ for (Keymapping *m = keymappings; m; m = m->next){ KeySym u = NoSymbol; KeySym l = NoSymbol; XConvertCase(k, &l, &u); /* Note that magic bit manipulation here - we want to check that the * modifiers that are specified for the binding are all pressed, but * we allow other modifiers to be as well. This is because when NumLock * is on, it's always added to the modifier mask. */ if (l == m->s || m->s == XK_VoidSymbol){ if (m->m == 0 || (m->m & ~e->xkey.state) == 0){ switch (m->c){ case Cnone: return; case Cdefault: continue; default: f = ((GwinWidget)w)->gwin.gotchar; if (f) (*f)(m->c, m->k, Tcurrent, 0, 0, m->a); return; } } } } /* * The following song and dance is so we can have our chosen * modifier key behave like a compose key, i.e, press and release * and then type the compose sequence, like Plan 9. We have * to find out which key is the compose key first though. */ if (IsModifierKey(k) && ((GwinWidget)w)->gwin.compose && composing == -2 && modmap) { minmod = (((GwinWidget)w)->gwin.compose+2)*keypermod; for (c = minmod; c < minmod+keypermod; c++) { XtTranslateKeycode(e->xany.display, modmap->modifiermap[c], e->xkey.state, &md, &mk); if (k == mk) { composing = -1; break; } } return; } /* Handle Multi_key separately, since it isn't a modifier */ if(k == XK_Multi_key) { composing = -1; return; } if(k == NoSymbol || k > 0xff00) return; /* Check to see if we are in a composition sequence */ if (!((GwinWidget)w)->gwin.compose && (e->xkey.state & Mod1Mask) && composing == -2) composing = -1; if (composing > -2) { compose[++composing] = k; if ((*compose == 'X') && (composing > 0)) { if ((k < '0') || (k > 'f') || ((k > '9') && (k < 'a'))) { STUFFCOMPOSE(); c = (uint16_t)k; composing = -2; } else if (composing == 4) { c = unicode(compose); if (c == -1) { STUFFCOMPOSE(); c = (uint16_t)compose[4]; } composing = -2; } } else if (composing == 1) { c = (int)latin1(compose); if (c == -1) { STUFFCOMPOSE(); c = (uint16_t)compose[1]; } composing = -2; } } else { if (composing >= 0) { composing++; STUFFCOMPOSE(); } c = keysymtoshort(k); composing = -2; } if (composing >= -1) return; f = ((GwinWidget)w)->gwin.gotchar; if(f) (*f)(c, kind, Tcurrent, 0, 0, NULL); }