コード例 #1
0
static int _lastNonTrailingIndexOfPathSeparator(const VString& s, int& lengthWithoutTrailingSeparator) {
    bool hasTrailingPathSeparator = s.endsWith(VFSNode::PATH_SEPARATOR_CHAR);
    if (!hasTrailingPathSeparator) {
        lengthWithoutTrailingSeparator = s.length();
        return s.lastIndexOf(VFSNode::PATH_SEPARATOR_CHAR);
    }

    VString stripped;
    s.getSubstring(stripped, s.begin(), s.end() - 1);
    lengthWithoutTrailingSeparator = stripped.length();
    return stripped.lastIndexOf(VFSNode::PATH_SEPARATOR_CHAR);
}
コード例 #2
0
void VStreamsUnit::_testOverloadedStreamCopyAPIs() {
    // Test the overloaded streamCopy APIs.

    // 2 low-level VStream objects (VMemoryStream).
    // 2 high-level VIOStream objects that use them (VTextIOStream).
    VMemoryStream vstreamFrom;
    VMemoryStream vstreamTo;
    VTextIOStream viostreamFrom(vstreamFrom);
    VTextIOStream viostreamTo(vstreamTo);

    // Write a very long string into the source, and reset it.
    const VString EXAMPLE_STRING("This is a very long string that we will copy from stream to stream using different overloaded APIs.");
    viostreamFrom.writeString(EXAMPLE_STRING);
    viostreamFrom.seek0();

    // Copy 10 bytes at a time, using each of the 4 overloaded APIs.
    // 1. VStream to VStream
    VStream::streamCopy(vstreamFrom, vstreamTo, 10);
    // 2. VIOStream to VIOStream
    VStream::streamCopy(viostreamFrom, viostreamTo, 10);
    // 3. VIOStream to VStream
    VStream::streamCopy(viostreamFrom, vstreamTo, 10);
    // 4. VStream to VIOStream
    VStream::streamCopy(vstreamFrom, viostreamTo, 10);

    // Verify that the data was correctly copied.

    viostreamTo.seek0();
    VUNIT_ASSERT_EQUAL_LABELED(viostreamTo.available(), CONST_S64(40), "all 40 bytes copied");

    VString whatWasCopied;
    viostreamTo.readAll(whatWasCopied);
    VString whatShouldHaveBeenCopied;
    EXAMPLE_STRING.getSubstring(whatShouldHaveBeenCopied, 0, 40);
    VUNIT_ASSERT_EQUAL_LABELED(whatWasCopied, whatShouldHaveBeenCopied, "correct substring was copied");
}