Beispiel #1
0
size_t split_line(SplitStringLine *result, unsigned wid, std::wstring_view str, size_t offset, unsigned options) {
	str.remove_prefix(offset);
	const wchar_t *s = str.data();
	size_t slen = str.length();

	size_t cur = 0;     // Current position
	unsigned curwid = 0;// Used screen width

	for (;;) {
		if (cur >= slen) {
			result->begin = offset;
			result->len = slen;
			result->wid = curwid;
			return (offset + slen);
		}
		if (!(options & SPLIT_NEWLINE_AS_SPACE) && s[cur] == L'\n') {
			result->begin = offset;
			result->len = cur;
			result->wid = curwid;
			return (offset + cur + 1); // Skip the newline character
		}
		unsigned w = ucs_width (s[cur]);
		if (curwid + w > wid) {
			break;
		}
		curwid += w;
		++cur;
	}
	// Not the whold string. Neither has a newline character been encountered
	// Now scan backward to find a proper line-breaking point
	unsigned extra_skip = 0;
	if (!(options & SPLIT_CUT_WORD)) {
		unsigned xcur = cur;
		for (;;) {
			if (xcur == 0) { // This means that a single word is longer than a line. We have to split it
				break;
			}
			if ((!ucs_isalnum (s[xcur-1]) || !ucs_isalnum (s[xcur])) &&
					allow_line_end (s[xcur-1]) &&
					allow_line_beginning (s[xcur])) {
				cur = xcur;
				break;
			}
			curwid -= ucs_width (s[--xcur]);
		}
		while (cur+extra_skip+1<slen && s[cur+extra_skip]==L' ') {
			++extra_skip;
		}
	}
	result->begin = offset;
	result->len = cur;
	result->wid = curwid;
	return (offset + cur + extra_skip);
}
void CConfigAppearance::AddFontName(std::wstring_view Name)		// // //
{
	if (Name.size() >= LF_FACESIZE)		// // //
		return;

	CComboBox *pFontList = static_cast<CComboBox*>(GetDlgItem(IDC_FONT));

	pFontList->AddString(Name.data());

	if (m_strFont == Name)
		pFontList->SelectString(0, Name.data());
}
Beispiel #3
0
SplitStringLineList split_line(unsigned wid, std::wstring_view s) {
	SplitStringLineList ret;
	if (wid < 2) { // Robustness. Avoid dead loops
		for (size_t k = 0; k < s.length(); ++k) {
			ret.push_back({k, 1, ucs_width(s[k])});
		}
	} else {
		for (unsigned offset = 0; offset < s.length(); ) {
			SplitStringLine line;
			offset = split_line(&line, wid, s, offset, 0);
			ret.push_back(std::move(line));
		}
	}
	return ret;
}
Beispiel #4
0
// Routine Description:
// - writes text to the screen
// Arguments:
// - screenInfo - the screen info to write to
// - chars - the text to write to the screen
// - target - the starting coordinate in the screen
// - used - number of elements written
// Return Value:
// - S_OK, E_INVALIDARG or similar HRESULT error.
[[nodiscard]]
HRESULT ApiRoutines::WriteConsoleOutputCharacterWImpl(IConsoleOutputObject& OutContext,
                                                      const std::wstring_view chars,
                                                      const COORD target,
                                                      size_t& used) noexcept
{
    // Set used to 0 from the beginning in case we exit early.
    used = 0;

    if (chars.empty())
    {
        return S_OK;
    }

    LockConsole();
    auto Unlock = wil::scope_exit([&] { UnlockConsole(); });

    auto& screenInfo = OutContext.GetActiveBuffer();
    const auto bufferSize = screenInfo.GetBufferSize();
    if (!bufferSize.IsInBounds(target))
    {
        return E_INVALIDARG;
    }

    try
    {
        OutputCellIterator it(chars);
        const auto finished = screenInfo.Write(it, target);
        used = finished.GetInputDistance(it);
    }
    CATCH_RETURN();

    return S_OK;
}
Beispiel #5
0
unsigned split_line (SplitStringLine *result, unsigned max_lines, unsigned wid, std::wstring_view s) {
	unsigned offset = 0;
	unsigned lines = 0;
	for (; lines < max_lines && offset < s.length(); ++lines) {
		offset = split_line(result++, wid, s, offset, 0);
	}
	return lines;
}
Beispiel #6
0
std::unordered_map<std::wstring_view, std::wstring_view> splitData(const std::wstring_view &data)
{
    std::unordered_map<std::wstring_view, std::wstring_view> out;
    size_t start = 0;
    for (size_t end = data.find(L";", start); end != std::wstring::npos;
         start = end + 1, end = data.find(L";", start)) {
        if (start == end) {
            end = data.size();
        }
        const std::wstring_view tmp(data.data() + start, end - start);
        const auto pos = tmp.find(L"=");
        out[tmp.substr(0, pos)] = tmp.substr(pos + 1);
        // tLog << L"'" << tmp.substr(0, pos) << L"' = '" << tmp.substr(pos + 1) << L"'";
    }
    return out;
}
Beispiel #7
0
 bool operator()(std::wstring_view lhs, std::wstring_view rhs) const {
   if (_wcsicmp(lhs.data(), rhs.data()) < 0)
     return true;
   return false;
 }
	static expected<random_access_stream, hresult_error> create_on_file(std::wstring_view file_path, ABI::Windows::Storage::FileAccessMode acc){
		return detail::convert_to_rich_interface<random_access_stream>(com_create_resource<ABI::Windows::Storage::Streams::IRandomAccessStream>([&](ABI::Windows::Storage::Streams::IRandomAccessStream** ptr){return ::CreateRandomAccessStreamOnFile(file_path.data(), acc, ABI::Windows::Storage::Streams::IID_IRandomAccessStream, reinterpret_cast<void**>(ptr));}), _T(__FUNCTION__));
	}
Beispiel #9
0
std::string utf16_to_utf8(std::wstring_view wtext)
{
   std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
   std::string text = converter.to_bytes(wtext.data());
   return text;
}