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); }
void printBinaryHll(ServerInterface& srvInterface, const char* prefix, const VString& hll) { return; unsigned int i; char buf_str[10000]; char* buf_ptr = buf_str; if (!hll.isNull()) { for (i = 0; i < hll.length(); i++) { buf_ptr += sprintf(buf_ptr, "%02X ", hll.data()[i]); } } *(buf_ptr + 1) = '\0'; srvInterface.log("%s: %d %s", prefix, hll.length(), buf_str); }
bool VDirAdapter::extractFileName(const VString &strFilePath, VString &strName, VString &strTitle) const { bool bResult = false; size_t nLength = strFilePath.length(); strName = strFilePath; size_t nPos = strName.rfind("."); size_t nCount = nPos; size_t nOffset = 0; if (nPos == 0) strTitle = ""; else strTitle = strFilePath.substr(nOffset, nCount); m_bExtractName = true; return bResult; }
bool VDirAdapter::findFile(const VString &strPath) { if (strPath.empty() || strPath == "") return false; #ifdef UNICODE WCHAR wszPath[512] = {0}; ::MultiByteToWideChar(CP_UTF8, 0, strPath.c_str(), strPath.length(), wszPath, sizeof(wszPath)); m_hFindFile = ::FindFirstFile(wszPath, &m_FindFileData); #else m_hFindFile = ::FindFirstFile(strPath.c_str(), &m_FindFileData); #endif extractRoot(strPath, m_strRoot); m_bExtractName = false; return (m_hFindFile != INVALID_HANDLE_VALUE); }
bool VDirAdapter_Unix::extractExt(const VString &strName, VString &strExt) { bool bResult = false; size_t nPos = strName.rfind("."); if (nPos != -1) { bResult = true; size_t nLength = strName.length(); size_t nCount = nLength - nPos - 1; size_t nOffset = nPos + 1; strExt = strName.substr(nOffset, nCount); } else { bResult = false; } return bResult; }
VCodePoint::VCodePoint(const VString& hexNotation) : mIntValue(0) , mUTF8Length(0) , mUTF16Length(0) { // If the string starts with "U+" we skip it. // From there we assume the rest is hexadecimal, at most 8 digits. int length = hexNotation.length(); int start = 0; if (hexNotation.startsWith("U+")) { start += 2; } if (length - start > 8) { throw VRangeException(VSTRING_FORMAT("VCodePoint: attempt to construct with invalid notation '%s'.", hexNotation.chars())); } // Walk backwards until we process all characters or see the '+'. int valueByteIndex = 0; for (VString::const_reverse_iterator ri = hexNotation.rbegin(); ri != hexNotation.rend(); /*incremented below*/) { //for (int index = length-1; index >= start; ) { VCodePoint nextChar = *ri; ++ri; if (nextChar == '+') { break; } VCodePoint lowNibbleChar = nextChar; VCodePoint highNibbleChar('0'); if (ri != hexNotation.rend()) { nextChar = *ri; ++ri; if (nextChar != '+') { highNibbleChar = nextChar; } } if (!highNibbleChar.isHexadecimal() || !lowNibbleChar.isHexadecimal()) { throw VRangeException(VSTRING_FORMAT("VCodePoint: attempt to construct with invalid notation '%s'.", hexNotation.chars())); } // At this point we have the two hex chars. Convert to a byte, and or it into the result at the appropriate location. Vs32 byteValue = (Vs32) VHex::hexCharsToByte((char) highNibbleChar.intValue(), (char) lowNibbleChar.intValue()); // char TODO: VHex API update to VCodePoint byteValue <<= (valueByteIndex * 8); Vs32 mask = 0x000000FF << (valueByteIndex * 8); mIntValue |= (int) (byteValue & mask); ++valueByteIndex; if (nextChar == '+') { break; } } mUTF8Length = VCodePoint::getUTF8LengthFromCodePointValue(mIntValue); mUTF16Length = VCodePoint::getUTF16LengthFromCodePointValue(mIntValue); }
void addItemToHll(void* hll, const VString& item) { SerializedHyperLogLog* phll = (SerializedHyperLogLog*)hll; phll->add(item.data(), item.length()); }
void SimpleHllAggregateFunctionBase::addItem(ServerInterface &srvInterface, void* hll, const VString& item) { HllHolder* phll = (HllHolder*)hll; if (phll->hll == NULL) phll->hll = (SerializedHyperLogLog*)createNewHll(); phll->hll->add(item.data(), item.length()); }