OSDN Git Service

crystaledit: Reduce MFC dependency
[winmerge-jp/winmerge-jp.git] / Externals / crystaledit / editlib / utils / filesup.cpp
1 ///////////////////////////////////////////////////////////////////////////
2 //  File:    filesup.cpp
3 //  Version: 1.1.0.4
4 //  Updated: 19-Jul-1998
5 //
6 //  Copyright:  Ferdinand Prantl
7 //  E-mail:     prantl@ff.cuni.cz
8 //
9 //  Some handy stuff to deal with files and their names
10 //
11 //  You are free to use or modify this code to the following restrictions:
12 //  - Acknowledge me somewhere in your about box, simple "Parts of code by.."
13 //  will be enough. If you can't (or don't want to), contact me personally.
14 //  - LEAVE THIS HEADER INTACT
15 ////////////////////////////////////////////////////////////////////////////
16
17 #include "pch.h"
18 #include "filesup.h"
19
20 ////////////////////////////////////////////////////////////////////////////////
21
22 int GetExtPosition (const tchar_t* pszString)
23 {
24   if (pszString == nullptr || !*pszString)
25     return 0;
26   const std::basic_string<tchar_t> sString = pszString;
27   int len = static_cast<int>(sString.length ()), posit = len;
28   tchar_t test;
29   do
30     if ((test = sString.at (--posit)) == _T ('.'))
31       return posit;
32 #ifdef _UNICODE
33   while (posit && test != _T ('\\') && test != _T (':'));
34 #else
35   while (posit && (test != _T ('\\') || _ismbstrail((unsigned char *)pszString, (unsigned char *)pszString + posit)) && test != _T (':'));
36 #endif
37   return len;
38 }
39
40 std::basic_string<tchar_t> GetExt (const std::basic_string<tchar_t>& sString)
41 {
42   std::basic_string<tchar_t> sString2 = sString;
43   if (!sString2.empty ())
44     {
45       sString2 = sString2.substr (GetExtPosition (sString2.c_str ()));
46       if (!sString2.empty () && sString2[0] == _T ('.'))
47         {
48           sString2 = sString2.substr (1);
49         }
50     }
51   return sString2;
52 }
53
54 ////////////////////////////////////////////////////////////////////////////////