本文整理汇总了C++中SourceRange::length方法的典型用法代码示例。如果您正苦于以下问题:C++ SourceRange::length方法的具体用法?C++ SourceRange::length怎么用?C++ SourceRange::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SourceRange
的用法示例。
在下文中一共展示了SourceRange::length方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: disableProperty
void InspectorStyleTextEditor::disableProperty(unsigned index)
{
ASSERT(!m_allProperties->at(index).disabled);
const InspectorStyleProperty& property = m_allProperties->at(index);
InspectorStyleProperty disabledProperty(property);
disabledProperty.setRawTextFromStyleDeclaration(m_styleText);
disabledProperty.disabled = true;
SourceRange removedRange;
unsigned insertedLength;
internalReplaceProperty(property, "", &removedRange, &insertedLength);
// If some preceding formatting has been removed, move the property to the start of the removed range.
if (property.sourceData.range.start > removedRange.start)
disabledProperty.sourceData.range.start = removedRange.start;
disabledProperty.sourceData.range.end = disabledProperty.sourceData.range.start;
// Add disabled property at correct position.
unsigned insertionIndex = disabledIndexByOrdinal(index, true);
if (insertionIndex == UINT_MAX)
m_disabledProperties->append(disabledProperty);
else {
m_disabledProperties->insert(insertionIndex, disabledProperty);
long styleLengthDelta = -(static_cast<long>(removedRange.length()));
shiftDisabledProperties(insertionIndex + 1, styleLengthDelta); // Property removed from text - shift these back.
}
}
示例2: replaceProperty
void InspectorStyleTextEditor::replaceProperty(unsigned index, const String& newText)
{
ASSERT_WITH_SECURITY_IMPLICATION(index < m_allProperties->size());
const InspectorStyleProperty& property = m_allProperties->at(index);
long propertyStart = property.sourceData.range.start;
long propertyEnd = property.sourceData.range.end;
long oldLength = propertyEnd - propertyStart;
long newLength = newText.length();
long propertyLengthDelta = newLength - oldLength;
if (!property.disabled) {
SourceRange overwrittenRange;
unsigned insertedLength;
internalReplaceProperty(property, newText, &overwrittenRange, &insertedLength);
propertyLengthDelta = static_cast<long>(insertedLength) - static_cast<long>(overwrittenRange.length());
// Recompute subsequent disabled property ranges if acting on a non-disabled property.
shiftDisabledProperties(disabledIndexByOrdinal(index, true), propertyLengthDelta);
} else {
long textLength = newText.length();
unsigned disabledIndex = disabledIndexByOrdinal(index, false);
if (!textLength) {
// Delete disabled property.
m_disabledProperties->remove(disabledIndex);
} else {
// Patch disabled property text.
m_disabledProperties->at(disabledIndex).rawText = newText;
}
}
}
示例3: enableProperty
void InspectorStyleTextEditor::enableProperty(unsigned index)
{
ASSERT(m_allProperties->at(index).disabled);
unsigned disabledIndex = disabledIndexByOrdinal(index, false);
ASSERT(disabledIndex != UINT_MAX);
InspectorStyleProperty disabledProperty = m_disabledProperties->at(disabledIndex);
m_disabledProperties->remove(disabledIndex);
SourceRange removedRange;
unsigned insertedLength;
internalReplaceProperty(disabledProperty, disabledProperty.rawText, &removedRange, &insertedLength);
shiftDisabledProperties(disabledIndex, static_cast<long>(insertedLength) - static_cast<long>(removedRange.length()));
}