示例#1
1
/*
 * @implemented
 */
void CHString::MakeReverse() throw (CHeap_Exception)
{
    // We'll modify string, duplicate it first if needed
    CopyBeforeWrite();

    // Let's use appropriate helper
    _wcsrev(m_pchData);
}
示例#2
0
WCHAR *commasput(int what)
{
    WCHAR *ret = (WCHAR *)malloc(sizeof(WCHAR) * 21);
    int i, j;
    for (i = 0, j = 0; what; what /= 10, i++, j++) {
        if (j % 3 == 0 && j)
            ret[i++] = _T(',');
        ret[i] = what % 10 + _T('0');
    }
    ret[i] = 0;
    return _wcsrev(ret);
}
/*	Limited length number prints.	*/
VOID LNPrintXY(SIZE_T Num,INT LenghtLimit,INT x,INT y){
	INT i;
	WCHAR Temp[MAX_PATH];
	WCHAR	Text[LONGEST_64BIT_NUM];
	for(i=0;Num>0;++i,Num/=10)
		Text[i] = Num%10 + '0';
	if(i==0)
		Text[i++]='0';
	Text[i]='\0';
	_wcsrev(Text);
	if(wcslen(Text) <=  (size_t)LenghtLimit)
		PrintXY(Text,x,y);
	else{
		for(i=0;i<LenghtLimit - 3;++i)
			Temp[i] = Text[i];
		Temp[i]='\0';
		wcscat(Temp,TEXT("..."));
		PrintXY(Temp,x,y);
	}
}
示例#4
0
HRESULT COMCALL CustomTracer::TestMethod(BSTR bstrInput, BSTR* pbstrOutput)
{
	LOG_ENTRY(TXT("CustomTracer::TestMethod()"));

	HRESULT hr = S_OK;

	try
	{
		// Check output parameters.
		if (pbstrOutput == nullptr)
			throw WCL::ComException(E_POINTER, TXT("pbstrOutput is NULL"));

		// Reverse the input string.
		*pbstrOutput = _wcsrev(::SysAllocString(BSTR2W(bstrInput)));
	}
	COM_CATCH(hr)

	LOG_EXIT(TXT("HRESULT=0x%08X [%s]"), hr, CStrCvt::FormatError(hr).c_str());

	return hr;
}
示例#5
0
/*----------------------------------------------------------------------------*/
char* scistrrev(char* str)
{
    char *revstr = NULL;
    if (str)
    {
        wchar_t *wcstr = to_wide_string(str);
#ifdef _MSC_VER
        wchar_t *wcrevstr = _wcsrev(wcstr);
        revstr = wide_string_to_UTF8(wcrevstr);
#else
        int i = 0;
        int t = 0;
        int j = 0, k = 0;

        if (wcstr)
        {
            i = (int)wcslen(wcstr);
        }
        t = !(i % 2) ? 1 : 0;   // check the length of the string .

        /* copy character by character to reverse string */
        k = 0;
        for (j = i - 1; j > (i / 2 - t) ; j-- )
        {
            /* j starts from end of string */
            /* k starts from beginning of string */
            wchar_t ch  = wcstr[j]; /* ch temp. character */
            wcstr[j]   = wcstr[k]; /* end and beginning characters are exchanged */
            wcstr[k++] = ch;
        }
        revstr = wide_string_to_UTF8(wcstr);
#endif
        FREE(wcstr);
    }
    return revstr;
}
void CCOMStringW::MakeReverse()
{
	_wcsrev(m_pszString);
}
示例#7
0
BOOL FileReverse(PCTSTR pszPathname, PBOOL pbIsTextUnicode) {

   *pbIsTextUnicode = FALSE;  // Assume text is Unicode

   // Open the file for reading and writing.
   HANDLE hFile = CreateFile(pszPathname, GENERIC_WRITE | GENERIC_READ, 0, 
      NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

   if (hFile == INVALID_HANDLE_VALUE) {
      chMB("File could not be opened.");
      return(FALSE);
   }

   // Get the size of the file (I assume the whole file can be mapped).
   DWORD dwFileSize = GetFileSize(hFile, NULL);

   // Create the file-mapping object. The file-mapping object is 1 character 
   // bigger than the file size so that a zero character can be placed at the 
   // end of the file to terminate the string (file). Because I don't yet know
   // if the file contains ANSI or Unicode characters, I assume worst case
   // and add the size of a WCHAR instead of CHAR.
   HANDLE hFileMap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 
      0, dwFileSize + sizeof(WCHAR), NULL);

   if (hFileMap == NULL) {
      chMB("File map could not be opened.");
      CloseHandle(hFile);
      return(FALSE);
   }

   // Get the address where the first byte of the file is mapped into memory.
   PVOID pvFile = MapViewOfFile(hFileMap, FILE_MAP_WRITE, 0, 0, 0);

   if (pvFile == NULL) {
      chMB("Could not map view of file.");
      CloseHandle(hFileMap);
      CloseHandle(hFile);
      return(FALSE);
   }

   // Does the buffer contain ANSI or Unicode?
   int iUnicodeTestFlags = -1;   // Try all tests
   *pbIsTextUnicode = IsTextUnicode(pvFile, dwFileSize, &iUnicodeTestFlags);

   if (!*pbIsTextUnicode) {
      // For all the file manipulations below, we explicitly use ANSI 
      // functions because we are processing an ANSI file.

      // Put a zero character at the very end of the file.
      PSTR pchANSI = (PSTR) pvFile;
      pchANSI[dwFileSize / sizeof(CHAR)] = 0;

      // Reverse the contents of the file.
      _strrev(pchANSI);

      // Convert all "\n\r" combinations back to "\r\n" to 
      // preserve the normal end-of-line sequence.
      pchANSI = strstr(pchANSI, "\n\r"); // Find first "\r\n".

      while (pchANSI != NULL) {
         // We have found an occurrence....
         *pchANSI++ = '\r';   // Change '\n' to '\r'.
         *pchANSI++ = '\n';   // Change '\r' to '\n'.
         pchANSI = strstr(pchANSI, "\n\r"); // Find the next occurrence.
      }

   } else {
      // For all the file manipulations below, we explicitly use Unicode
      // functions because we are processing a Unicode file.

      // Put a zero character at the very end of the file.
      PWSTR pchUnicode = (PWSTR) pvFile;
      pchUnicode[dwFileSize / sizeof(WCHAR)] = 0;

      if ((iUnicodeTestFlags & IS_TEXT_UNICODE_SIGNATURE) != 0) {
         // If the first character is the Unicode BOM (byte-order-mark), 
         // 0xFEFF, keep this character at the beginning of the file.
         pchUnicode++;
      }

      // Reverse the contents of the file.
      _wcsrev(pchUnicode);

      // Convert all "\n\r" combinations back to "\r\n" to 
      // preserve the normal end-of-line sequence.
      pchUnicode = wcsstr(pchUnicode, L"\n\r"); // Find first '\n\r'.

      while (pchUnicode != NULL) {
         // We have found an occurrence....
         *pchUnicode++ = L'\r';   // Change '\n' to '\r'.
         *pchUnicode++ = L'\n';   // Change '\r' to '\n'.
         pchUnicode = wcsstr(pchUnicode, L"\n\r"); // Find the next occurrence.
      }
   }

   // Clean up everything before exiting.
   UnmapViewOfFile(pvFile);
   CloseHandle(hFileMap);

   // Remove trailing zero character added earlier.
   SetFilePointer(hFile, dwFileSize, NULL, FILE_BEGIN);
   SetEndOfFile(hFile);
   CloseHandle(hFile);

   return(TRUE);
}