void SourceEdit::PasteCode(const wchar_t* code) { // Process escapes in the code string size_t len = wcslen(code); CStringW theCode; theCode.Preallocate((int)len); for (size_t i = 0; i < len; i++) { wchar_t c = code[i]; if (c == '[') { int unicode = 0; if (swscanf(code+i,L"[=0x%x=]",&unicode) == 1) { theCode.AppendChar((wchar_t)unicode); i += 9; continue; } } theCode.AppendChar(c); } CString theCodeUtf = TextFormat::UnicodeToUTF8(theCode); CallEdit(SCI_REPLACESEL,0,(sptr_t)(LPCSTR)theCodeUtf); }
CStringW CSecRunAsUser::CreateRandomPW(){ CStringW strResult; while (strResult.GetLength() < 10){ char chRnd = (char)(48 + (rand() % 74)); if( (chRnd > 97 && chRnd < 122) || (chRnd > 65 && chRnd < 90) || (chRnd >48 && chRnd < 57) ||(chRnd==95) ){ strResult.AppendChar(chRnd); } } return strResult; }
CStringW Skein::Node::StripWhite(const CStringW& inStr) { CStringW outStr; outStr.Preallocate(inStr.GetLength()+1); for (int i = 0; i < inStr.GetLength(); i++) { WCHAR c = inStr.GetAt(i); switch (c) { case L'\n': case L'\r': case L' ': case L'\t': break; case '>': if (i < inStr.GetLength()-1) outStr.AppendChar(c); default: outStr.AppendChar(c); break; } } return outStr; }
bool SourceEdit::GetNextLine(const CStringW& text, CStringW& line, int& i) { if (i == text.GetLength()) { // If at the very end, the final line must be blank line = ""; i++; return true; } else if (i > text.GetLength()) { // Past the end of the text, so stop reading lines return false; } line.Empty(); while (i < text.GetLength()) { WCHAR c = text.GetAt(i); i++; switch (c) { case L'\r': // Check for a "\r\n" sequence if (i < text.GetLength()) { if (text.GetAt(i) == L'\n') i++; } return true; case L'\n': return true; default: line.AppendChar(c); break; } } // Having got here a line must have ended without a trailing carriage return, // so move beyond the end of text to make sure this is the last line. i++; return true; }