Example #1
0
wxSize wxGridCellStringRenderer::DoGetBestSize(const wxGridCellAttr& attr,
                                               wxDC& dc,
                                               const wxString& text)
{
    wxCoord x = 0, y = 0, max_x = 0;
    dc.SetFont(attr.GetFont());
    wxStringTokenizer tk(text, wxT('\n'));
    while ( tk.HasMoreTokens() )
    {
        dc.GetTextExtent(tk.GetNextToken(), &x, &y);
        max_x = wxMax(max_x, x);
    }

    y *= 1 + text.Freq(wxT('\n')); // multiply by the number of lines.

    return wxSize(max_x, y);
}
bool CRCppEmitter::HasBrokenInString (const wxString &line) const
{
    int freq = line.Freq ('"');
    return (freq % 2 == 1);
}
Example #3
0
void DebuggerTree::ParseEntry(WatchTreeEntry& entry, Watch* watch, wxString& text, long array_index)
{
    if (text.IsEmpty())
        return;
//    Manager::Get()->GetLogManager()->DebugLog(F(_T("DebuggerTree::ParseEntry(): %s"), text.c_str()));
    while (1)
    {
        // trim the string from left and right
        text.Trim(true);
        text.Trim(false);

        // find position of '{', '}' and ',' ***outside*** of any quotes.
        // decide which is nearer to the start
        int braceOpenPos = FindCharOutsideQuotes(text, _T('{'));
        if (braceOpenPos == -1)    braceOpenPos = 0xFFFFFE;
        int braceClosePos = FindCharOutsideQuotes(text, _T('}'));
        if (braceClosePos == -1) braceClosePos = 0xFFFFFE;
        int commaPos = FindCommaPos(text);
        if (commaPos == -1) commaPos = 0xFFFFFE;
        int pos = std::min(commaPos, std::min(braceOpenPos, braceClosePos));

        if (pos == 0xFFFFFE)
        {
            // no comma, opening or closing brace
            if (text.Right(3).Matches(_T(" = ")))
                text.Truncate(text.Length() - 3);
            if (!text.IsEmpty())
            {
                entry.AddChild(text, watch);
                text.Clear();
            }
            break;
        }
        else
        {
            // display array on a single line?
            // normal (multiple lines) display is taken care below, with array indexing
            if (watch &&
                watch->is_array &&
                braceOpenPos != 0xFFFFFE &&
                braceClosePos != 0xFFFFFE)
            {
                wxString tmp = text.Left(braceClosePos + 1);
                // if more than one opening/closing brace, then it's a complex array so
                // ignore single-line
                if (text.Freq(_T('{')) == 1 && text.Freq(_T('}')) == 1)
                {
                    // array on single line for up to 8 (by default) elements
                    // if more elements, fall through to the multi-line display
                    int commas = Manager::Get()->GetConfigManager(_T("debugger"))->ReadInt(_T("/single_line_array_elem_count"), 8);
                    if (tmp.Freq(_T(',')) < commas)
                    {
                        // array watch type
                        tmp[braceOpenPos] = _T('[');
                        tmp.Last() = _T(']');
                        entry.AddChild(tmp, watch);
                        text.Remove(0, braceClosePos + 1);
                        continue;
                    }
                }
            }

            wxString tmp = text.Left(pos);
            WatchTreeEntry* newchild = 0;

            if (tmp.Right(3).Matches(_T(" = ")))
                tmp.Truncate(tmp.Length() - 3); // remove " = " if last in string
            if (!tmp.IsEmpty())
            {
                // take array indexing into account (if applicable)
                if (array_index != -1)
                {
                    tmp.Prepend(wxString::Format(_T("[%ld]: "), array_index));
                    // if array element would occur multiple times, gdb adds as default "<repeated xx times> to the output
                    // so we have to look for it and increase the array_index correctly
                    // as default we increase by 1
                    long incIndex = 1;
                    if (reRepeatedElements.Matches(tmp))
                    {
                        reRepeatedElements.GetMatch(tmp, 1).ToLong(&incIndex);
                    }
                    array_index += incIndex;
                }

                newchild = &entry.AddChild(tmp, watch);
            }
            text.Remove(0, pos + 1);

            if (pos == braceOpenPos)
            {
                if (!newchild)
                    newchild = &entry;

                // enable array indexing (if applicable)
                bool no_indexing = array_index == -1;
                if (watch && watch->is_array && no_indexing &&
                    text.Freq(_T('{')) == 0 && text.Freq(_T('}')) == 1) // don't index complex arrays
                {
                    array_index = 0;
                }

                ParseEntry(*newchild, watch, text, array_index); // proceed one level deeper

                // reset array indexing
                if (no_indexing)
                    array_index = -1;
            }
            else if (pos == braceClosePos)
                break; // return one level up
        }
    }
}