Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.3 KiB

  1. #ifndef _CREATEEMAILNAME
  2. #define _CREATEEMAILNAME
  3. CString CreateEmailName(LPCTSTR psName);
  4. const TCHAR ALLOWED_CHARS[] = _T("!#$%^'()-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz{}~");
  5. inline CString CreateEmailName(LPCTSTR psName)
  6. {
  7. CString sBuildName = _T("");
  8. if( !psName )
  9. return sBuildName; // length of psName handled below
  10. int iSize = _tcslen(psName);
  11. LPTSTR psBuildName = new TCHAR[iSize + 1];
  12. LPTSTR psChar = new TCHAR[2];
  13. if( (0 < iSize) && psBuildName && psChar )
  14. {
  15. int i, j = 0;
  16. ZeroMemory( psChar, 2 * sizeof(TCHAR) );
  17. ZeroMemory( psBuildName, ( iSize + 1 ) * sizeof( TCHAR ));
  18. LPTSTR psResult = NULL;
  19. for ( i = 0; i < iSize; i++ )
  20. {
  21. _tcsncpy( psChar, &(psName[i]), 1 );
  22. psResult = _tcspbrk( psChar, ALLOWED_CHARS );
  23. if( psResult )
  24. {
  25. psBuildName[j++] = psName[i];
  26. }
  27. }
  28. sBuildName = psBuildName;
  29. }
  30. else
  31. sBuildName = psName;
  32. if( psBuildName )
  33. {
  34. delete [] psBuildName;
  35. psBuildName = NULL;
  36. }
  37. if( psChar )
  38. {
  39. delete [] psChar;
  40. psChar = NULL;
  41. }
  42. return sBuildName;
  43. }
  44. #endif //_CREATEEMAILNAME