コード例 #1
0
ファイル: Print.cpp プロジェクト: ismaelbelghiti/MetaCode
void Print::PrintDebug(int level) {
   printIndent(level);
   std::cout << "Print : ";
   for(int iPrintable = 0; iPrintable < GetNbPrintables(); iPrintable++) {
      GetPrintable(iPrintable)->PrintDebug();
      std::cout << " ";
   }	 
   if(WithEndline())
      std::cout << "endline";
}
コード例 #2
0
ファイル: Path.cpp プロジェクト: geekt/amule
wxString CPath::TruncatePath(size_t length, bool isFilePath) const
{
	wxString file = GetPrintable();

	// Check if there's anything to do
	if (file.Length() <= length) {
		return file;
	}

	// If the path is a file name, then prefer to remove from the path, rather than the filename
	if (isFilePath) {
		wxString path = wxFileName(file).GetPath();
		file          = wxFileName(file).GetFullName();

		if (path.Length() >= length) {
			path.Clear();
		} else if (file.Length() >= length) {
			path.Clear();
		} else {
			// Minus 6 for "[...]" + separator
			int pathlen = (int)(length - file.Length() - 6);

			if (pathlen > 0) {
				path = wxT("[...]") + path.Right( pathlen );
			} else {
				path.Clear();
			}
		}

		file = ::JoinPaths(path, file);
	}

	if (file.Length() > length) {
		if (length > 5) {
			file = file.Left(length - 5) + wxT("[...]");
		} else {
			file.Clear();
		}
	}

	return file;
}
コード例 #3
0
bool
ReadStringAndDumpToStream<StringElementType::ASCII> (ReadStringAndDumpToStreamOptions options)
{
    assert(options.GetStream() && "need a Stream to print the string to");
    Error my_error;

    ProcessSP process_sp(options.GetProcessSP());

    if (process_sp.get() == nullptr || options.GetLocation() == 0)
        return false;

    size_t size;

    if (options.GetSourceSize() == 0)
        size = process_sp->GetTarget().GetMaximumSizeOfStringSummary();
    else if (!options.GetIgnoreMaxLength())
        size = std::min(options.GetSourceSize(),process_sp->GetTarget().GetMaximumSizeOfStringSummary());
    else
        size = options.GetSourceSize();

    lldb::DataBufferSP buffer_sp(new DataBufferHeap(size,0));

    process_sp->ReadCStringFromMemory(options.GetLocation(), (char*)buffer_sp->GetBytes(), size, my_error);

    if (my_error.Fail())
        return false;

    char prefix_token = options.GetPrefixToken();
    char quote = options.GetQuote();

    if (prefix_token != 0)
        options.GetStream()->Printf("%c%c",prefix_token,quote);
    else if (quote != 0)
        options.GetStream()->Printf("%c",quote);

    uint8_t* data_end = buffer_sp->GetBytes()+buffer_sp->GetByteSize();

    // since we tend to accept partial data (and even partially malformed data)
    // we might end up with no NULL terminator before the end_ptr
    // hence we need to take a slower route and ensure we stay within boundaries
    for (uint8_t* data = buffer_sp->GetBytes(); *data && (data < data_end);)
    {
        if (options.GetEscapeNonPrintables())
        {
            uint8_t* next_data = nullptr;
            auto printable = GetPrintable(StringElementType::ASCII, data, data_end, next_data);
            auto printable_bytes = printable.GetBytes();
            auto printable_size = printable.GetSize();
            if (!printable_bytes || !next_data)
            {
                // GetPrintable() failed on us - print one byte in a desperate resync attempt
                printable_bytes = data;
                printable_size = 1;
                next_data = data+1;
            }
            for (unsigned c = 0; c < printable_size; c++)
                options.GetStream()->Printf("%c", *(printable_bytes+c));
            data = (uint8_t*)next_data;
        }
        else
        {
            options.GetStream()->Printf("%c",*data);
            data++;
        }
    }

    if (quote != 0)
        options.GetStream()->Printf("%c",quote);

    return true;
}