Esempio n. 1
0
void ARMv7DOpcode::appendRegisterList(unsigned registers)
{
    unsigned numberPrinted = 0;

    appendCharacter('{');

    for (unsigned i = 0; i < 16; i++) {
        if (registers & (1 << i)) {
            if (numberPrinted++)
                appendSeparator();
            appendRegisterName(i);
        }
    }

    appendCharacter('}');
}
Esempio n. 2
0
void ARMv7DOpcode::appendInstructionName(const char* instructionName, bool addS)
{
    if (!inITBlock()  && !addS) {
        appendInstructionNameNoITBlock(instructionName);

        return;
    }

    const char sevenSpaces[8] = "       ";

    unsigned length = strlen(instructionName);

    bufferPrintf("   %s", instructionName);
    if (inITBlock()) {
        const char* condition = conditionName(m_currentITCondition);
        length += strlen(condition);
        appendString(condition);
    } else if (addS) {
        length++;
        appendCharacter('s');
    }

    if (length >= 7)
        length = 6;

    appendString(sevenSpaces + length);
}
Esempio n. 3
0
void UrlBar::handleKeyReleaseEvent(const XKeyReleasedEvent& event)
{
    char normalKey;
    KeySym specialKey;

    XLookupString(const_cast<XKeyEvent*>(&event), &normalKey, sizeof(char), &specialKey, 0);

    switch (specialKey) {
    case XK_BackSpace:
        removeCharacter();
        break;
    case XK_Delete:
        deleteCharacter();
        break;
    case XK_Home:
        m_cursorPosition = 0;
        break;
    case XK_End:
        m_cursorPosition = m_url.length();
        break;
    case XK_Left:
        if (m_cursorPosition)
            m_cursorPosition--;
        break;
    case XK_Right:
        if (m_cursorPosition < m_url.length())
            m_cursorPosition++;
        break;
    case XK_Return:
        loadPage();
        break;
    case XK_Insert:
        if (event.state & ControlMask)
            becomeClipboardOwner();
        else if (event.state & ShiftMask)
            requestClipboardText();
        break;
    default:
        if (event.state & ControlMask) {
            // while the Control key is pressed, character codes start from 1 (A=1, B=2, ...).
            switch (normalKey + 'A' - 1) {
            case 'C':
                becomeClipboardOwner();
                break;
            case 'V':
                requestClipboardText();
                break;
            }
        } else
            appendCharacter(normalKey);

        break;
    }

    drawUrlBar();
}
Esempio n. 4
0
const char* ARMv7DOpcodeLoadStoreRegisterImmediate::format()
{
    const char* instructionName = opName();

    if (!instructionName)
        return defaultFormat();

    appendInstructionName(opName());
    appendRegisterName(rt());
    appendSeparator();
    appendCharacter('[');
    appendRegisterName(rn());
    if (immediate5()) {
        appendSeparator();
        appendUnsignedImmediate(immediate5() << scale());
    }
    appendCharacter(']');

    return m_formatBuffer;
}
Esempio n. 5
0
bool UITextEdit::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks)
{
    if(UIWidget::onKeyPress(keyCode, keyboardModifiers, autoRepeatTicks))
        return true;

    if(keyboardModifiers == Fw::KeyboardNoModifier) {
        if(keyCode == Fw::KeyDelete) { // erase right character
            removeCharacter(true);
            return true;
        } else if(keyCode == Fw::KeyBackspace) { // erase left character {
            removeCharacter(false);
            return true;
        } else if(keyCode == Fw::KeyRight && !m_shiftNavigation) { // move cursor right
            moveCursor(true);
            return true;
        } else if(keyCode == Fw::KeyLeft && !m_shiftNavigation) { // move cursor left
            moveCursor(false);
            return true;
        } else if(keyCode == Fw::KeyHome) { // move cursor to first character
            setCursorPos(0);
            return true;
        } else if(keyCode == Fw::KeyEnd) { // move cursor to last character
            setCursorPos(m_text.length());
            return true;
        } else if(keyCode == Fw::KeyTab && !m_shiftNavigation) {
            if(UIWidgetPtr parent = getParent())
                parent->focusNextChild(Fw::KeyboardFocusReason);
            return true;
        } else if(keyCode == Fw::KeyEnter && m_multiline) {
            appendCharacter('\n');
            return true;
        } else if(keyCode == Fw::KeyUp && !m_shiftNavigation && m_multiline) {
            
        } else if(keyCode == Fw::KeyDown && !m_shiftNavigation && m_multiline) {

        }
    } else if(keyboardModifiers == Fw::KeyboardCtrlModifier) {
        if(keyCode == Fw::KeyV) {
            appendText(g_window.getClipboardText());
            return true;
        }
    } else if(keyboardModifiers == Fw::KeyboardShiftModifier) {
        if(keyCode == Fw::KeyRight && m_shiftNavigation) { // move cursor right
            moveCursor(true);
            return true;
        } else if(keyCode == Fw::KeyLeft && m_shiftNavigation) { // move cursor left
            moveCursor(false);
            return true;
        }
    }

    return false;
}
Esempio n. 6
0
bool TextCodecUTF8::handlePartialSequence<UChar>(UChar*& destination, const uint8_t*& source, const uint8_t* end, bool flush, bool stopOnError, bool& sawError)
{
    ASSERT(m_partialSequenceSize);
    do {
        if (isASCII(m_partialSequence[0])) {
            *destination++ = m_partialSequence[0];
            consumePartialSequenceByte();
            continue;
        }
        int count = nonASCIISequenceLength(m_partialSequence[0]);
        if (!count) {
            handleError(destination, stopOnError, sawError);
            if (stopOnError)
                return false;
            continue;
        }
        if (count > m_partialSequenceSize) {
            if (count - m_partialSequenceSize > end - source) {
                if (!flush) {
                    // The new data is not enough to complete the sequence, so
                    // add it to the existing partial sequence.
                    memcpy(m_partialSequence + m_partialSequenceSize, source, end - source);
                    m_partialSequenceSize += end - source;
                    return false;
                }
                // An incomplete partial sequence at the end is an error.
                handleError(destination, stopOnError, sawError);
                if (stopOnError)
                    return false;
                continue;
            }
            memcpy(m_partialSequence + m_partialSequenceSize, source, count - m_partialSequenceSize);
            source += count - m_partialSequenceSize;
            m_partialSequenceSize = count;
        }
        int character = decodeNonASCIISequence(m_partialSequence, count);
        if (character == nonCharacter) {
            handleError(destination, stopOnError, sawError);
            if (stopOnError)
                return false;
            continue;
        }

        m_partialSequenceSize -= count;
        destination = appendCharacter(destination, character);
    } while (m_partialSequenceSize);

    return false;
}
Esempio n. 7
0
void SuffixTrie:: buildSuffixTrie(const string& T)
{
   auxiliary = new Node();
   root = new Node();

   for(int i = 0; i < MAX_NUM_ELEMENTS; ++i)
   {
      auxiliary->nodes[i] = root;
   }

   root->suffix_link = auxiliary;   

   top = root;

   for(int i = 0; i < T.size(); ++i)
   {
      appendCharacter(T[i]);
   }  
}
Esempio n. 8
0
void UrlBar::pasteClipboardText(const XEvent &event)
{
    Atom clipType;
    int clipFormat;
    unsigned long clipLength;
    unsigned long clipRemainingBytes;
    unsigned char *clipBuffer = 0;

    if (event.xselection.property == None)
        return;

    XGetWindowProperty(m_display, m_window,
        event.xselection.property, 0, 255, False, AnyPropertyType,
        &clipType, &clipFormat, &clipLength, &clipRemainingBytes, &clipBuffer);

    for (unsigned long i = 0; i < clipLength; i++)
        appendCharacter(clipBuffer[i]);

    XFree(clipBuffer);
}
Esempio n. 9
0
String TextCodecUTF8::decode(const char* bytes, size_t length, bool flush, bool stopOnError, bool& sawError)
{
    // Each input byte might turn into a character.
    // That includes all bytes in the partial-sequence buffer because
    // each byte in an invalid sequence will turn into a replacement character.
    StringBuffer<LChar> buffer(m_partialSequenceSize + length);

    const uint8_t* source = reinterpret_cast<const uint8_t*>(bytes);
    const uint8_t* end = source + length;
    const uint8_t* alignedEnd = alignToMachineWord(end);
    LChar* destination = buffer.characters();

    do {
        if (m_partialSequenceSize) {
            // Explicitly copy destination and source pointers to avoid taking pointers to the
            // local variables, which may harm code generation by disabling some optimizations
            // in some compilers.
            LChar* destinationForHandlePartialSequence = destination;
            const uint8_t* sourceForHandlePartialSequence = source;
            if (handlePartialSequence(destinationForHandlePartialSequence, sourceForHandlePartialSequence, end, flush, stopOnError, sawError)) {
                source = sourceForHandlePartialSequence;
                goto upConvertTo16Bit;
            }
            destination = destinationForHandlePartialSequence;
            source = sourceForHandlePartialSequence;
            if (m_partialSequenceSize)
                break;
        }

        while (source < end) {
            if (isASCII(*source)) {
                // Fast path for ASCII. Most UTF-8 text will be ASCII.
                if (isAlignedToMachineWord(source)) {
                    while (source < alignedEnd) {
                        MachineWord chunk = *reinterpret_cast_ptr<const MachineWord*>(source);
                        if (!isAllASCII<LChar>(chunk))
                            break;
                        copyASCIIMachineWord(destination, source);
                        source += sizeof(MachineWord);
                        destination += sizeof(MachineWord);
                    }
                    if (source == end)
                        break;
                    if (!isASCII(*source))
                        continue;
                }
                *destination++ = *source++;
                continue;
            }
            int count = nonASCIISequenceLength(*source);
            int character;
            if (!count)
                character = nonCharacter;
            else {
                if (count > end - source) {
                    ASSERT_WITH_SECURITY_IMPLICATION(end - source < static_cast<ptrdiff_t>(sizeof(m_partialSequence)));
                    ASSERT(!m_partialSequenceSize);
                    m_partialSequenceSize = end - source;
                    memcpy(m_partialSequence, source, m_partialSequenceSize);
                    source = end;
                    break;
                }
                character = decodeNonASCIISequence(source, count);
            }
            if (character == nonCharacter) {
                sawError = true;
                if (stopOnError)
                    break;

                goto upConvertTo16Bit;
            }
            if (character > 0xff)
                goto upConvertTo16Bit;

            source += count;
            *destination++ = character;
        }
    } while (flush && m_partialSequenceSize);

    buffer.shrink(destination - buffer.characters());

    return String::adopt(buffer);

upConvertTo16Bit:
    StringBuffer<UChar> buffer16(m_partialSequenceSize + length);

    UChar* destination16 = buffer16.characters();

    // Copy the already converted characters
    for (LChar* converted8 = buffer.characters(); converted8 < destination;)
        *destination16++ = *converted8++;

    do {
        if (m_partialSequenceSize) {
            // Explicitly copy destination and source pointers to avoid taking pointers to the
            // local variables, which may harm code generation by disabling some optimizations
            // in some compilers.
            UChar* destinationForHandlePartialSequence = destination16;
            const uint8_t* sourceForHandlePartialSequence = source;
            handlePartialSequence(destinationForHandlePartialSequence, sourceForHandlePartialSequence, end, flush, stopOnError, sawError);
            destination16 = destinationForHandlePartialSequence;
            source = sourceForHandlePartialSequence;
            if (m_partialSequenceSize)
                break;
        }

        while (source < end) {
            if (isASCII(*source)) {
                // Fast path for ASCII. Most UTF-8 text will be ASCII.
                if (isAlignedToMachineWord(source)) {
                    while (source < alignedEnd) {
                        MachineWord chunk = *reinterpret_cast_ptr<const MachineWord*>(source);
                        if (!isAllASCII<LChar>(chunk))
                            break;
                        copyASCIIMachineWord(destination16, source);
                        source += sizeof(MachineWord);
                        destination16 += sizeof(MachineWord);
                    }
                    if (source == end)
                        break;
                    if (!isASCII(*source))
                        continue;
                }
                *destination16++ = *source++;
                continue;
            }
            int count = nonASCIISequenceLength(*source);
            int character;
            if (!count)
                character = nonCharacter;
            else {
                if (count > end - source) {
                    ASSERT_WITH_SECURITY_IMPLICATION(end - source < static_cast<ptrdiff_t>(sizeof(m_partialSequence)));
                    ASSERT(!m_partialSequenceSize);
                    m_partialSequenceSize = end - source;
                    memcpy(m_partialSequence, source, m_partialSequenceSize);
                    source = end;
                    break;
                }
                character = decodeNonASCIISequence(source, count);
            }
            if (character == nonCharacter) {
                sawError = true;
                if (stopOnError)
                    break;
                // Each error generates a replacement character and consumes one byte.
                *destination16++ = replacementCharacter;
                ++source;
                continue;
            }
            source += count;
            destination16 = appendCharacter(destination16, character);
        }
    } while (flush && m_partialSequenceSize);

    buffer16.shrink(destination16 - buffer16.characters());

    return String::adopt(buffer16);
}
Esempio n. 10
0
bool UITextEdit::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks)
{
    if(UIWidget::onKeyPress(keyCode, keyboardModifiers, autoRepeatTicks))
        return true;

    if(keyboardModifiers == Fw::KeyboardNoModifier) {
        if(keyCode == Fw::KeyDelete && m_editable) { // erase right character
            if(hasSelection() || !m_text.empty()) {
                del(true);
                return true;
            }
        } else if(keyCode == Fw::KeyBackspace && m_editable) { // erase left character
            if(hasSelection() || !m_text.empty()) {
                del(false);
                return true;
            }
        } else if(keyCode == Fw::KeyRight && !m_shiftNavigation) { // move cursor right
            clearSelection();
            moveCursorHorizontally(true);
            return true;
        } else if(keyCode == Fw::KeyLeft && !m_shiftNavigation) { // move cursor left
            clearSelection();
            moveCursorHorizontally(false);
            return true;
        } else if(keyCode == Fw::KeyHome) { // move cursor to first character
            if(m_cursorPos != 0) {
                clearSelection();
                setCursorPos(0);
                return true;
            }
        } else if(keyCode == Fw::KeyEnd) { // move cursor to last character
            if(m_cursorPos != (int)m_text.length()) {
                clearSelection();
                setCursorPos(m_text.length());
                return true;
            }
        } else if(keyCode == Fw::KeyTab && !m_shiftNavigation) {
            clearSelection();
            if(UIWidgetPtr parent = getParent())
                parent->focusNextChild(Fw::KeyboardFocusReason, true);
            return true;
        } else if(keyCode == Fw::KeyEnter && m_multiline && m_editable) {
            appendCharacter('\n');
            return true;
        } else if(keyCode == Fw::KeyUp && !m_shiftNavigation && m_multiline) {
            moveCursorVertically(true);
            return true;
        } else if(keyCode == Fw::KeyDown && !m_shiftNavigation && m_multiline) {
            moveCursorVertically(false);
            return true;
        }
    } else if(keyboardModifiers == Fw::KeyboardCtrlModifier) {
        if(keyCode == Fw::KeyV && m_editable) {
            paste(g_window.getClipboardText());
            return true;
        } else if(keyCode == Fw::KeyX && m_editable && m_selectable) {
            if(hasSelection()) {
                cut();
                return true;
            }
        } else if(keyCode == Fw::KeyC && m_selectable) {
            if(hasSelection()) {
                copy();
                return true;
            }
        } else if(keyCode == Fw::KeyA && m_selectable) {
            if(m_text.length() > 0) {
                selectAll();
                return true;
            }
        }
    } else if(keyboardModifiers == Fw::KeyboardShiftModifier) {
        if(keyCode == Fw::KeyTab && !m_shiftNavigation) {
            if(UIWidgetPtr parent = getParent())
                parent->focusPreviousChild(Fw::KeyboardFocusReason, true);
            return true;
        } else if(keyCode == Fw::KeyRight || keyCode == Fw::KeyLeft) {

            int oldCursorPos = m_cursorPos;

            if(keyCode == Fw::KeyRight) // move cursor right
                moveCursorHorizontally(true);
            else if(keyCode == Fw::KeyLeft) // move cursor left
                moveCursorHorizontally(false);

            if(m_shiftNavigation)
                clearSelection();
            else {
                if(!hasSelection())
                    m_selectionReference = oldCursorPos;
                setSelection(m_selectionReference, m_cursorPos);
            }
            return true;
        } else if(keyCode == Fw::KeyHome) { // move cursor to first character
            if(m_cursorPos != 0) {
                setSelection(m_cursorPos, 0);
                setCursorPos(0);
                return true;
            }
        } else if(keyCode == Fw::KeyEnd) { // move cursor to last character
            if(m_cursorPos != (int)m_text.length()) {
                setSelection(m_cursorPos, m_text.length());
                setCursorPos(m_text.length());
                return true;
            }
        }
    }

    return false;
}