Exemplo n.º 1
0
QChar HTML::resolveEntity(const QString &entity)
{
    HtmlEntity* he = (HtmlEntity*) qBinaryFind(start_first,end_first,entity);
    if (he != end_first) return he->code;
    he = (HtmlEntity*) qBinaryFind(start_ent,end_ent,entity);
    if (he == end_ent) return QChar();
    return he->code;
}
Exemplo n.º 2
0
/*!
    return layout offset for a \a filePath, \a layout, \a section.

    Only acceptable separator for filePath is '/'.
*/
int HbSharedCache::layoutDefinitionOffset(const QString &filePath,
                                          const QString &layout,
                                          const QString &section) const
{
    int offset = -1;
    int position = 0;
    int length = filePath.length();
    if (filePath.at(0) == ':') {
        //resource css use only file name as a key.
        int index = filePath.lastIndexOf('/');
        if (index >= 0) {
            position = index + 1;
            length = filePath.length() - position;
        }
    }
    if (mOffsetItemCount > 0) {
        //try first in prebuilt offset map.
        length -= WidgetMLFileExtension.length();
        QStringRef widgetname(&filePath, position, length);
        HbOffsetItem find(hash(widgetname));
        const HbOffsetItem *end = mOffsetItems + mOffsetItemCount;
        const HbOffsetItem *offsetItem = qBinaryFind(mOffsetItems, end, find);
        if (offsetItem != end) {
#ifdef CSSBIN_TRACES
            qDebug() << "Offset item found from static cache map for widget: " << widgetname;
#endif
            int tableSize = 0;
            const HbLayoutIndexItem *begin = layoutIndexItemBegin(
                    offsetItem->offsetLayoutIndexTable, &tableSize);
            if (begin) {
                const HbLayoutIndexItem *end = begin + tableSize;
                HbLayoutIndexItem find(hash(QStringRef(&layout)), hash(QStringRef(&section)));
                const HbLayoutIndexItem *item = qBinaryFind(begin, end, find);
                if (item != end) {
#ifdef CSSBIN_TRACES
                    qDebug() << "Layout definition offset found for layout: " << layout;
#endif
                    offset = item->offset;
                }
            }
        }
    }
    if (offset == -1) {
        QStringRef filePathRef(&filePath, position, filePath.length() - position);
        QString key;
        key.reserve(filePathRef.length() + 2 //key separators
                    + layout.length() + section.length());
        key.append(filePathRef)
           .append(KeySeparator)
           .append(layout)
           .append(KeySeparator)
           .append(section);
        offset = findOffsetFromDynamicMap(LayoutDefinition, QStringRef(&key));
    }
    return offset;
}
Exemplo n.º 3
0
void QuickViewFilterModel::load() const
{
    if(m_loaded)
        return;
    m_filteredRows.clear();
    m_historyHash.clear();
    m_historyHash.reserve(sourceModel()->rowCount());
    m_scaleTime = QDateTime::currentDateTime();
    for(int i = 0; i < sourceModel()->rowCount(); ++i) {
        QModelIndex idx = sourceModel()->index(i, 0);
        QString url = idx.data(HistoryModel::UrlStringRole).toString();
        const QUrl qUrl(url);
        // we keep Arora's internal URLs away from here
        if(isValid(qUrl)) {
            if(!m_historyHash.contains(qUrl.host())) {
                int sourceOffset = sourceModel()->rowCount() - i;
                m_filteredRows.append(HistoryData(sourceOffset, frecencyScore(idx)));
                m_historyHash.insert(qUrl.host(), sourceOffset);
            } else {
                // we already know about this url: just increment its frecency score
                QList<HistoryData>::iterator pos = qBinaryFind(m_filteredRows.begin(),
                                                   m_filteredRows.end(), HistoryData(m_historyHash[qUrl.host()], -1));
                Q_ASSERT(pos != m_filteredRows.end());
                pos->frecency += frecencyScore(idx);
            }
        }
    }
    m_loaded = true;
}
Exemplo n.º 4
0
void QuickViewFilterModel::sourceRowsInserted(const QModelIndex &parent, int start, int end)
{
    Q_ASSERT(start == end && start == 0);
    Q_UNUSED(end);
    if(!m_loaded)
        return;
    QModelIndex idx = sourceModel()->index(start, 0, parent);
    QString url = idx.data(HistoryModel::UrlStringRole).toString();
    const QUrl qUrl(url);
    int currentFrecency = 0;
    if(m_historyHash.contains(qUrl.host())) {
        QList<HistoryData>::iterator pos = qBinaryFind(m_filteredRows.begin(),
                                           m_filteredRows.end(), HistoryData(m_historyHash[qUrl.host()], -1));
        Q_ASSERT(pos != m_filteredRows.end());
        int realRow = pos - m_filteredRows.begin();
        currentFrecency = pos->frecency;
        beginRemoveRows(QModelIndex(), realRow, realRow);
        m_filteredRows.erase(pos);
        m_historyHash.remove(qUrl.host());
        endRemoveRows();
    }
    beginInsertRows(QModelIndex(), 0, 0);
    m_filteredRows.insert(0, HistoryData(sourceModel()->rowCount(), frecencyScore(idx) + currentFrecency));
    m_historyHash.insert(qUrl.host(), sourceModel()->rowCount());
    endInsertRows();
}
Exemplo n.º 5
0
static const CppSyntaxHighlighter::Keyword *findKeyword(const QString &word)
{
    const CppSyntaxHighlighter::Keyword *start = &CppSyntaxHighlighter::keywords[0];
    const CppSyntaxHighlighter::Keyword *end = &CppSyntaxHighlighter::keywords[MAX_KEYWORD - 1];
    const CppSyntaxHighlighter::Keyword *kw = qBinaryFind(start, end, word);
    return kw;
}
Exemplo n.º 6
0
static QChar macSymbolForQtKey(int key)
{
    const MacSpecialKey *i = qBinaryFind(entries, MacSpecialKeyEntriesEnd, key);
    if (i == MacSpecialKeyEntriesEnd)
        return QChar();
    return QChar(i->macSymbol);
}
Exemplo n.º 7
0
void PythonCompletionObject::fetchIdentifierType()
{
    // Scilab's typeof function could be used here, but as long as these lists
    // are used just looking up the name is easier.

    if (qBinaryFind(PythonKeywords::instance()->functions().begin(),
		    PythonKeywords::instance()->functions().end(), identifier())
	!= PythonKeywords::instance()->functions().end())
	emit fetchingTypeDone(FunctionType);
    else if (qBinaryFind(PythonKeywords::instance()->keywords().begin(),
			 PythonKeywords::instance()->keywords().end(), identifier())
	!= PythonKeywords::instance()->keywords().end())
	emit fetchingTypeDone(KeywordType);
    else
	emit fetchingTypeDone(VariableType);
}
Exemplo n.º 8
0
static inline QPrinter::PaperSize string2PaperSize(const char *name)
{
    const NamedPaperSize *r = qBinaryFind(named_sizes_map, named_sizes_map + QPrinter::NPageSize, name);
    if (r - named_sizes_map != QPrinter::NPageSize)
        return r->size;
    return QPrinter::Custom;
}
Exemplo n.º 9
0
static bool is_blacklisted(const QByteArray& appname)
{
    const char* const* begin = &blackList[0];
    const char* const* end = &blackList[sizeof(blackList)/sizeof(*blackList)]-1;

    // ### binary search
    return qBinaryFind(begin, end, appname.data()) != end;
}
Exemplo n.º 10
0
Task SmartNameCache::findTask( TaskId id ) const
{
    const TaskList::ConstIterator it = qBinaryFind( m_tasks.begin(), m_tasks.end(), Task( id, QString() ), IdLessThan() );
    if ( it != m_tasks.constEnd() )
        return *it;
    else
        return Task();
}
Exemplo n.º 11
0
void SmartNameCache::deleteTask( const Task& task )
{
    const TaskList::Iterator it = qBinaryFind( m_tasks.begin(), m_tasks.end(), Task( task.id(), QString() ), IdLessThan() );
    if ( it != m_tasks.constEnd() ) {
        m_tasks.erase( it );
        regenerateSmartNames();
    }
}
Exemplo n.º 12
0
void SmartNameCache::modifyTask( const Task& task )
{
    const TaskList::Iterator it = qBinaryFind( m_tasks.begin(), m_tasks.end(), Task( task.id(), QString() ), IdLessThan() );
    if ( it != m_tasks.constEnd() )
        *it = task;
    sortTasks();
    regenerateSmartNames();
}
Exemplo n.º 13
0
int main() {
  QList<int> numbers;
  numbers << 1 << 5 << 6 << 7 << 9 << 11;
  QList<int>::iterator it;
  it = qBinaryFind(numbers.begin(), numbers.end(), 6);
  // it == numbers.begin() + 2
  qDebug() << *it; // 6
  numbers.clear();
  numbers << 1 << 6 << 6 << 6 << 9 << 11;
  it = qBinaryFind(numbers.begin(), numbers.end(), 6);
  // it == numbers.begin() + 1 or
  // it == numbers.begin() + 2 or
  // it == numbers.begin() + 3
  qDebug() << *it;

  return 0;
}
static bool isKeyword(const QString &word)
{
    const char * const *start = &keywords[0];
    const char * const *end = &keywords[MAX_KEYWORD - 1];
    const char * const *kw = qBinaryFind(start, end, KeywordHelper(word));

    return kw != end;
}
Exemplo n.º 15
0
void QueryModel::mapperEntryFound(QString entry)
{
    if (d_cancelled)
        return;
    
    // find position in d_results using the word index
    int idx = d_valueIndex.value(entry, -1);
        
    if (idx == -1)
    {
        idx = d_results.size();
        d_results.append(QPair<QString,int>(entry, 1));
        d_valueIndex[entry] = idx;

        HitsCompare compare(*this);
        
        // find new position, just above the result with less hits.
        QList<int>::iterator insertPos = qLowerBound(
            d_hitsIndex.begin(), d_hitsIndex.end(), idx, compare);
        
        // insert at new position
        d_hitsIndex.insert(insertPos, idx);
        
        emit layoutChanged(); // notify tableview that we have new rows
    }
    else
    {
        HitsCompare compare(*this);
        
        // Find the current position to remove
        
        // Binary search: does not work? Why not? :(
        QList<int>::iterator current_pos = qBinaryFind(
            d_hitsIndex.begin(), d_hitsIndex.end(), idx,
            compare);
        
        // It is already in the words index, it has to be in the hits index as well!
        assert(current_pos != d_hitsIndex.end());
        
        // remove from current position in the index
        d_hitsIndex.erase(current_pos);
        
        // Update hits index
        int hits = d_results[idx].second;
        d_results[idx].second = hits + 1;
        
        // find new position, just above the result with less hits.
        QList<int>::iterator insertPos = qLowerBound(
            d_hitsIndex.begin(), d_hitsIndex.end(), idx, compare);
        
        // insert at new position
        d_hitsIndex.insert(insertPos, idx);
    }
    
    ++d_totalHits;
    
    emit dataChanged(index(idx, 0), index(idx + 1, 2));
}
Exemplo n.º 16
0
int QTextTablePrivate::findCellIndex(int fragment) const
{
    QFragmentFindHelper helper(pieceTable->fragmentMap().position(fragment),
                              pieceTable->fragmentMap());
    QList<int>::ConstIterator it = qBinaryFind(cells.begin(), cells.end(), helper);
    if (it == cells.end())
        return -1;
    return it - cells.begin();
}
Exemplo n.º 17
0
QVariant QVariantAnimationPrivate::valueAt(qreal step) const
{
    QVariantAnimation::KeyValues::const_iterator result =
        qBinaryFind(keyValues.begin(), keyValues.end(), qMakePair(step, QVariant()), animationValueLessThan);
    if (result != keyValues.constEnd())
        return result->second;

    return QVariant();
}
Exemplo n.º 18
0
static inline bool qt_get_named_xpm_rgb(const char *name_no_space, QRgb *rgb)
{
    const XPMRGBData *r = qBinaryFind(xpmRgbTbl, xpmRgbTbl + xpmRgbTblSize, name_no_space);
    if (r != xpmRgbTbl + xpmRgbTblSize) {
        *rgb = r->value;
        return true;
    } else {
        return false;
    }
}
Exemplo n.º 19
0
static bool get_named_rgb(const char *name_no_space, QRgb *rgb)
{
    QByteArray name = QByteArray(name_no_space).toLower();
    const RGBData *r = qBinaryFind(rgbTbl, rgbTbl + rgbTblSize, name.constData());
    if (r != rgbTbl + rgbTblSize) {
        *rgb = r->value;
        return true;
    }
    return false;
}
Exemplo n.º 20
0
QString WManager::currentLangId()
{
	static WLang langs[] = {
		{ "ar", 26 },
		{ "cs", 19 },
		{ "da", 4 },
		{ "de", 9 },
		{ "el", 27 },
		{ "en", 1 },
		{ "es", 2 },
		{ "fi", 11 },
		{ "fr", 3 },
		{ "hu", 20 },
		{ "it", 8 },
		{ "ja", 29 },
		{ "ko", 30 },
		{ "nl", 6 },
		{ "no", 7 },
		{ "pl", 21 },
		{ "pt_BR", 5 },
		{ "pt_PT", 5 },
		{ "ro", 18 },
		{ "ru", 25 },
		{ "sk", 17 },
		{ "sv", 10 },
		{ "tr", 31 },
		{ "zh_CN", 13 },
		{ "zh_TW", 12 }
	};
	int count = sizeof(langs) / sizeof(langs[0]);
	QByteArray name = QLocale().name().toLatin1();
	WLang noop = { name.constData(), 0 };
	WLang *lang = qBinaryFind(langs, langs + count, noop, isCStrLessThen);
	if (lang == langs + count && name.contains('_')) {
		name.truncate(name.indexOf('_'));
		noop.locale = name.constData();
		lang = qBinaryFind(langs, langs + count, noop, isCStrLessThen);
	}
	if (lang == langs + count)
		return QString();
	return QString::number(lang->id);
}
Exemplo n.º 21
0
void KateLineLayoutMap::insert(int realLine, const KateLineLayoutPtr& lineLayoutPtr)
{
  LineLayoutMap::iterator it =
    qBinaryFind(m_lineLayouts.begin(), m_lineLayouts.end(), LineLayoutPair(realLine,KateLineLayoutPtr()), lessThan);
  if (it != m_lineLayouts.end()) {
    (*it).second = lineLayoutPtr;
  } else {
    it = qUpperBound(m_lineLayouts.begin(), m_lineLayouts.end(), LineLayoutPair(realLine,KateLineLayoutPtr()), lessThan);
    m_lineLayouts.insert(it, LineLayoutPair(realLine, lineLayoutPtr));
  }
}
Exemplo n.º 22
0
void ChatChannelUsersModel::onStatusChanged(const qutim_sdk_0_3::Status &)
{
	Buddy *unit = static_cast<Buddy*>(sender());
	Q_ASSERT(unit);
	const Node node(unit);
	const QList<Node>::Iterator it = qBinaryFind(m_units.begin(), m_units.end(), node);
	if (it == m_units.end())
		return;
	int index = it - m_units.begin();
	dataChanged(createIndex(index, 0), createIndex(index, 0));
}
Exemplo n.º 23
0
static bool get_named_rgb_internal(const char *name_no_space, int *red, int *green, int *blue)
{
    QByteArray name = QByteArray(name_no_space).toLower();
    const RGBData *r = qBinaryFind(rgbTbl, rgbTbl + rgbTblSize, name.constData());
    if (r != rgbTbl + rgbTblSize) {
        getRed(r->value, red);
        getGreen(r->value, green);
        getBlue(r->value, blue);
        return true;
    }
    return false;
}
Exemplo n.º 24
0
void ChatChannelUsersModel::removeUnit(Buddy *unit)
{
	const Node node(unit);
	const QList<Node>::Iterator it = qBinaryFind(m_units.begin(), m_units.end(), node);
	if (it == m_units.end())
		return;
	int index = it - m_units.begin();
	beginRemoveRows(QModelIndex(), index, index);
	disconnect(unit, 0, this, 0);
	m_units.removeAt(index);
	endRemoveRows();
	emit countChanged(m_units.size());
}
Exemplo n.º 25
0
void Profiler::positionDone()
{
    Function *f = determineCurrentFunction(currentScriptId.isEmpty() ? -1 : currentScriptId.top());
    if (!f || currentLine.isEmpty())
        return;
    QList<Action>::iterator i = qBinaryFind(f->actions.begin(), f->actions.end(), Action(currentLine.top()));
    if (i == f->actions.end())
        return;

    suseconds_t current = getTimeOfDay();
    Action *action = &f->actions[i - f->actions.begin()];
    action->cost += current - instTime;
    instTime = current;
}
Exemplo n.º 26
0
void QGraphicsItemAnimationPrivate::insertUniquePair(qreal step, qreal value, QList<Pair> *binList, const char* method)
{
    if (step < 0.0 || step > 1.0) {
        qWarning("QGraphicsItemAnimation::%s: invalid step = %f", method, step);
        return;
    }

    Pair pair(step, value);

    QList<Pair>::iterator result = qBinaryFind(binList->begin(), binList->end(), pair);
    if (result != binList->end())
        result->value = value;
    else {
        *binList << pair;
        qSort(binList->begin(), binList->end());
    }
}
Exemplo n.º 27
0
//! [2]
QChar resolveEntity(const QString &entity)
{
    static const QLatin1String name_table[] = {
        "AElig", "Aacute", ..., "zwnj"
    };
    static const ushort value_table[] = {
        0x0061, 0x00c1, ..., 0x200c
    };
    int N = sizeof(name_table) / sizeof(name_table[0]);

    const QLatin1String *name = qBinaryFind(name_table, name_table + N,
                                            entity);
    int index = name - name_table;
    if (index == N)
        return QChar();

    return QChar(value_table[index]);
}
Exemplo n.º 28
0
void ChatSessionModel::onPriorityChanged(const int &oldPriority, const int &newPriority)
{
	Buddy *unit = static_cast<Buddy*>(sender());
	QList<Node>::Iterator it;
	it = qBinaryFind(m_units.begin(), m_units.end(), Node(unit, oldPriority));
	Q_ASSERT(it != m_units.end());
	const int from = it - m_units.begin();
	it = qLowerBound(m_units.begin(), m_units.end(), Node(unit, newPriority));
	int to = it - m_units.begin();
	m_units[from].priority = newPriority;
	if (beginMoveRows(QModelIndex(), from, from, QModelIndex(), to)) {
		if (to > from)
			--to;
		m_units.move(from, to);
		Q_ASSERT(m_units[to].unit == unit);;
		endMoveRows();
	}
}
Exemplo n.º 29
0
QModelIndex QuickViewFilterModel::mapFromSource(const QModelIndex &sourceIndex) const
{
    load();
    QString url = sourceIndex.data(HistoryModel::UrlStringRole).toString();
    const QUrl qUrl(url);
    if(!m_historyHash.contains(qUrl.host()))
        return QModelIndex();

    int sourceOffset = sourceModel()->rowCount() - sourceIndex.row();

    QList<HistoryData>::iterator pos = qBinaryFind(m_filteredRows.begin(),
                                       m_filteredRows.end(), HistoryData(sourceOffset, -1));

    if(pos == m_filteredRows.end())
        return QModelIndex();

    return createIndex(pos - m_filteredRows.begin(), sourceIndex.column(), sourceOffset);
}
Exemplo n.º 30
0
Function *Profiler::determineCurrentFunction(qint64 scriptId)
{
    if (currentFunctionLine.isEmpty())
        return 0;
    if (scriptIdCache == scriptId && currentFunctionCache
        && currentFunctionCache->startLine == currentFunctionLine.top())
        return currentFunctionCache;

    Object *object = &objects[scriptId];
    QList<Function>::iterator i;
    i = qBinaryFind(object->functions.begin(), object->functions.end(), Function(currentFunctionLine.top()));
    if (i == object->functions.end())
        return 0;
    int fn = (i - object->functions.begin());
    currentFunctionCache = &objects[scriptId].functions[fn];
    scriptIdCache = scriptId;
    return &objects[scriptId].functions[fn];
}