Esempio n. 1
0
static wchar_t *parseItem (TCollection *dc, wchar_t * &line, wchar_t *kwd, wchar_t *value)
{
	if (IsCharAlpha (*skipSpaces (line)))
	{
		wchar_t	*k = kwd;
		while (*line && IsCharAlpha (*line)) *k++ = *line++;
		*k = *value = 0;
		if (*skipSpaces (line) == L'=')
		{
			line++;
			if (!dc)
			{
				getWord (line, value);
			}
			else
			{
				wchar_t	buf[MAX_STR_LEN], *pv = value;
				getWord (line, buf);
				for (wchar_t *pch = buf; *pch;)
				{
					if (L'&' != *pch)
					{
						*pv++ = *pch++;
					}
					else
					{
						++pch;						//skip '&'
						wchar_t	name[MAX_STR_LEN], *pname = name;
						while (*pch && *pch != L';') *pname++ = *pch++;
						*pname = 0;

						//if (!*pch) complain about entity reference syntax;
						if (*pch) ++pch;	//skip
															///';
															///'
						for (size_t i = 0; i < dc->getCount (); ++i)
						{
							TDefine *d = (TDefine *) ((*dc)[i]);
							if (0 == wcscmp (d->name, name))
							{
								for (const wchar_t *pdv = d->value; *pdv;) *pv++ = *pdv++;
								break;
							}
						}

						//if (i == dc->getCount()) complain about undefined entity;
					}
				}

				*pv = 0;
			}
		}

		return (line);
	}

	return (NULL);
}
Esempio n. 2
0
int IsCaseMixed(const char *Str)
{
  while (*Str && !IsCharAlpha(*Str))
    Str++;
  int Case=IsCharLower(*Str);
  while (*(Str++))
    if (IsCharAlpha(*Str) && IsCharLower(*Str)!=Case)
      return TRUE;
  return FALSE;
}
Esempio n. 3
0
File: ut.c Progetto: amacal/ed
/** Function: Suche Zeichenkette in Zeichenkette **/
TCHAR *ut_strstr(const TCHAR *txt, const TCHAR *pat, BOOL matchCase, BOOL wholeWord)
  {
  TCHAR *h = (TCHAR*)txt;
  UINT patlen = lstrlen(pat);
  while ((h = matchCase ? _tcsstr(h,pat) : ut_strstri(h,pat)) != NULL) { // Es gibt kein lstrstr() in Windows
    if (!wholeWord || ((h==txt || !IsCharAlpha(*(h-1))) && !IsCharAlpha(*(h+patlen))))
      break;
    h += patlen;
    }
  return h;
  }
Esempio n. 4
0
File: path.c Progetto: BUGgs/FreeRDP
HRESULT PathCchStripPrefixW(PWSTR pszPath, size_t cchPath)
{
	BOOL hasPrefix;

	if (!pszPath)
		return E_INVALIDARG;

	if (cchPath < 4 || cchPath > PATHCCH_MAX_CCH)
		return E_INVALIDARG;

	hasPrefix = ((pszPath[0] == '\\') && (pszPath[1] == '\\') &&
		(pszPath[2] == '?') && (pszPath[3] == '\\')) ? TRUE : FALSE;

	if (hasPrefix)
	{
		if (cchPath < 6)
			return S_FALSE;

		if (cchPath < (lstrlenW(&pszPath[4]) + 1))
			return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);

		if (IsCharAlpha(pszPath[4]) && (pszPath[5] == ':')) /* like C: */
		{
			wmemmove_s(pszPath, cchPath, &pszPath[4], cchPath - 4);
			/* since the passed pszPath must not necessarily be null terminated
			 * and we always have enough space after the strip we can always
			 * ensure the null termination of the stripped result
			 */
			pszPath[cchPath - 4] = 0;
			return S_OK;
		}
	}

	return S_FALSE;
}
Esempio n. 5
0
/*************************************************************************
* Find if the string has any alpha char in it
*
*
*************************************************************************/
BOOL IsAlphaString(LPSTR lpsz)
	{
	BOOL rVal = FALSE;
	LPSTR	lpszNon;
	for (lpszNon = lpsz; ((*lpszNon != NULL) && !(rVal = IsCharAlpha(*lpszNon)));
		lpszNon = AnsiNext(lpszNon));
	return rVal;
  }
Esempio n. 6
0
char get_scode(char ch)
{
    char soundex_map[] ="01230120022455012623010202";
    if(!IsCharAlpha(ch))
        return(0);
    else
        return(soundex_map[(ch-'A')]);
}
Esempio n. 7
0
void CPenWidthsDlg::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	// TODO: Add your message handler code here and/or call default
	BOOL alpha = IsCharAlpha( (TCHAR)nChar );
	if (alpha)
		MessageBeep((UINT)-1);
	else
		CDialog::OnChar(nChar, nRepCnt, nFlags);
}
Esempio n. 8
0
void CParsedEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	WORD type;

	if (nChar < 0x20)
		type = PES_ALL;                         // always allow control chars
	else if (IsCharAlphaNumeric((TCHAR)nChar) && !IsCharAlpha((TCHAR)nChar))
		type = PES_NUMBERS;
	else if (IsCharAlpha((TCHAR)nChar))
		type = PES_LETTERS;
	else
		type = PES_OTHERCHARS;

	if (m_wParseStyle & type)
	{
		CEdit::OnChar(nChar, nRepCnt, nFlags);  // permitted
	}
	else
	{
		// illegal character - inform parent
		OnBadInput();
	}
}
Esempio n. 9
0
long CLicenseKey::Base36ToDec(LPCTSTR szSource)
{
	int nLast = _tcslen (szSource) -1 ;

	long nResult = 0;
	for (int i = nLast; i>=0 ; i-- )
	{
		TCHAR ch = szSource[i];
		long nDigit = 0;

		if (IsCharAlpha (ch))
           nDigit = ch  - _T('A') + 10;
		else
           nDigit = ch  - _T('0');
		
		nResult += nDigit *  static_cast<long>(pow (36., nLast - i));
	}

	return nResult;
}
Esempio n. 10
0
/* If the specified file path starts with / return it, otherwise
 * return path prepended with home directory */
static char *normalize_path(const char *fn) {

    pa_assert(fn);

#ifndef OS_IS_WIN32
    if (fn[0] != '/') {
#else
    if (strlen(fn) < 3 || !IsCharAlpha(fn[0]) || fn[1] != ':' || fn[2] != '\\') {
#endif
        char *homedir, *s;

        if (!(homedir = pa_get_home_dir_malloc()))
            return NULL;

        s = pa_sprintf_malloc("%s" PA_PATH_SEP "%s", homedir, fn);
        pa_xfree(homedir);

        return s;
    }

    return pa_xstrdup(fn);
}

/* Load a cookie from a file in the home directory. If the specified
 * path starts with /, use it as absolute path instead. */
int pa_authkey_load_auto(const char *fn, void *data, size_t length) {
    char *p;
    int ret;

    pa_assert(fn);
    pa_assert(data);
    pa_assert(length > 0);

    if (!(p = normalize_path(fn)))
        return -2;

    ret = pa_authkey_load(p, data, length);
    pa_xfree(p);

    return ret;
}
Esempio n. 11
0
LRESULT CNumericEntryDlg::OnCharEditMin(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	USES_CONVERSION;
	
	TCHAR ch = (TCHAR)wParam;
	
	if (wParam >= 0x20)
	{
		CComBSTR bstr;
		m_editMin.GetWindowText((BSTR&)bstr);
		
		if ((IsCharAlphaNumeric(ch) && !IsCharAlpha(ch)) || 
			(ch == _T('.') && bstr.Length() > 0 && wcsrchr(bstr, WCHAR('.')) == NULL))
			bHandled = FALSE;
		else
			MessageBeep(MB_OK);
	}
	else
	{
		bHandled = FALSE;
	}
	
	return 0;
}
Esempio n. 12
0
File: crt.cpp Progetto: kilitary/ss
int isalpha (int _c)
{
	return IsCharAlpha((TCHAR) _c);
}
Esempio n. 13
0
static wchar_t *getItem (wchar_t * &line, wchar_t *kwd, bool &group)
{
	group = true;

	bool	coment = true;
	while (coment)
	{
		if (*skipSpaces (line) == L'<')
		{
			if (line[1] == L'!')
			{
				if (line[2] == L'-')
				{
					if (line[3] == L'-')
					{
						line += 4;
						coment = true;
						while (*line)
						{
							if (line[0] == L'-')
								if (line[1] == L'-')
									if (line[2] == L'>')
									{
										line += 3;
										break;
									}

							line++;
						}
					}
					else
						coment = false;
				}
				else
					coment = false;
			}
			else
				coment = false;
		}
		else
			coment = false;
	}

	if (*skipSpaces (line) == L'<')
	{
		wchar_t	*stLine = line;
		wchar_t	*k = kwd;
		line++;
		if (*line && (*line == L'/')) *k++ = *line++;
		while (*line && IsCharAlpha (*line)) *k++ = *line++;
		*k = 0;
		k = --line;

		int inQuote = 0;
		while (*++line)
		{
			if (inQuote)
			{
				if (*line == L'\\' && line[1] == L'\"')
					line++;
				else if (*line == L'\"')
					inQuote = 0;
			}
			else
			{
				if (*line == L'>')
				{
					if (line > stLine)
					{
						--line;
						if (*line == L'/')
						{
							*line = 0;
							group = false;
						}

						line++;
					}

					*line = 0;
					line++;
					break;
				}
				else if (*line == L'\"')
					inQuote = 1;
			}
		}

		return (k);
	}

	return (NULL);
}
Esempio n. 14
0
bool is_alpha(wchar_t Char)
{
	return IsCharAlpha(Char) != FALSE;
}
Esempio n. 15
0
static bool IsAlpha(wxChar ch)
{
	return IsCharAlpha(ch);
}
Esempio n. 16
0
inline int __cdecl IsAlpha(wchar_t Ch) { return IsCharAlpha(Ch); }
Esempio n. 17
0
LRESULT CALLBACK EditProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
    static bool Tracking = false;

    switch (iMsg)
    {
    case WM_CREATE:
    {
        return 0;
    }
    case WM_MOUSEMOVE:
    {
        if (!Tracking)
        {
            Tracking = true;
            TRACKMOUSEEVENT TM;
            TM.cbSize = sizeof(TM);
            TM.dwFlags = TME_HOVER | TME_LEAVE;
            TM.dwHoverTime = HOVER_DEFAULT;
            TM.hwndTrack = hWnd;
            bool b = (bool)TrackMouseEvent(&TM);
        }
        return 0;
    }
    case WM_MOUSELEAVE:
    {
        Tracking = false;
        return 0;
    }
    case WM_MOUSEHOVER: //word detection
    {
        DWORD Index = SendMessage(hWnd, EM_CHARFROMPOS, wParam, lParam); //line = HIWORD, charindex = LOWORD
        int length = SendMessage(hWnd, EM_LINELENGTH, LOWORD(Index), 0);
        int x = LOWORD(lParam);
        int y = HIWORD(lParam);

        TCHAR* line = new TCHAR[length+1]();
        int linenum = HIWORD(Index);
        WORD* firstwordoftheline = (WORD*)line;
        *firstwordoftheline = length + 1;
        int len = SendMessage(hWnd, EM_GETLINE, HIWORD(Index), (LPARAM)line);


        DWORD charStart = SendMessage(hWnd, EM_LINEINDEX, HIWORD(Index), 0);

        int w_start, w_end;

        if (line[LOWORD(Index) - charStart] != ' ')
        {
            for (w_start = LOWORD(Index) - charStart; w_start >= 0; --w_start)
            {
                if (line[w_start] == ' ')
                {
                    break;
                }
            }
            ++w_start;
            for (w_end = LOWORD(Index) - charStart; w_end < length; ++w_end)
            {
                if (line[w_end] == ' ')
                {
                    line[w_end] = '\0';
                    break;
                }
            }

            while (w_start < w_end)
            {
                if (!IsCharAlpha(line[w_start]))
                    ++w_start;
                else if (!IsCharAlpha(line[w_end]))
                    --w_end;
                else break;
            }
            ++w_end;
            GetDefinition(line + w_start, w_end - w_start);

        }
        delete[] line;
        Tracking = false;
        return 0;
    }

    }
    return OldEditProc(hWnd, iMsg, wParam, lParam);
}
Esempio n. 18
0
inline Boolean IsAnsiDigit (char c) {return (IsCharAlphaNumeric (c) && !IsCharAlpha (c));}
int LIsAlpha (unsigned Ch)
{
	unsigned char c = Ch;
    OemToCharBuff ((char *) &c, (char *) &c, 1);
	return IsCharAlpha (c);
}
Esempio n. 20
0
File: net.cpp Progetto: begoon/stuff
/*
  Name: connect()

  Description: trys to connect directly to target server.

  Parameters:
         [in] SOCKET *s - pointer to socket that exists, but
                          not created with socket() call yet.
         [in] char *server - target server.

  Return value:
          ON SUCCESS - true.
          ON   ERROR - false.

  Revision: 16.01.2007
*/
bool net::connect(SOCKET *s, char *server)
{
  // check server parameter
  if(NULL == server) return false;
  if('\0' == *server) return false;

  // parse server = "host:port"
  char host[MAX_PATH] = "\0";
  char port[MAX_PATH] = "\0";

  char *pbeg = server;
  char *pcur = server;

  while(':' != *(++pcur));
  memcpy(host, pbeg, (pcur-pbeg));
  pcur++; // omit ':'
  pbeg = pcur; // begin with port
  while(0 != *(++pcur));
  memcpy(port, pbeg, (pcur-pbeg));

  // connect
  SOCKADDR_IN    addr;
  struct hostent *hp = NULL;

  memset(&addr, 0, sizeof(addr));
    addr.sin_family = AF_INET;
    addr.sin_port   = htons(atoi(port));

    if (IsCharAlpha(server[0]))
  {
    hp = gethostbyname(host);
    }
    else
  {
    unsigned int ip_addr = inet_addr(host);
    hp = gethostbyaddr((char *)&ip_addr,4,AF_INET);
    }

  if(hp == NULL) return false; // can't resolve
  
    memcpy(&(addr.sin_addr), hp->h_addr, hp->h_length);

  if((*s = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) return false;

  if(::connect(*s, (PSOCKADDR) &addr, sizeof(addr)) == SOCKET_ERROR)
  {
    net::disconnect(s);
    return false;
  }

#ifdef LOG_TO_FILE
  HANDLE hLogFile;

  // try to open existing
  hLogFile = CreateFile(LOG_FNAME, GENERIC_WRITE, (FILE_SHARE_READ | FILE_SHARE_WRITE), NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

  if(INVALID_HANDLE_VALUE == hLogFile)
  {
    // anyway - close handle from previous try!
    CloseHandle(hLogFile);
    // try to create file
    hLogFile = CreateFile(LOG_FNAME, GENERIC_WRITE, (FILE_SHARE_READ | FILE_SHARE_WRITE), NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  }

  if(INVALID_HANDLE_VALUE != hLogFile)
  {
    connectn++;
    char delimiter[1024];
    wsprintf(delimiter, "%s %lu %s", "\n\n<------| CONNECT: ", connectn ,"|------>\n\n");
    DWORD written;
    SetFilePointer(hLogFile, 0, NULL, FILE_END);
    WriteFile(hLogFile, delimiter, lstrlen(delimiter), &written, NULL);
  }

  CloseHandle(hLogFile);
#endif

  return true;
}
Esempio n. 21
0
BOOL CMatrixDoc::StringsToMatrixs(CString * pVar,CTypedPtrList<CObList,CArrayMatrix *> & m_List,int num)
{
	for(int i=0;i<num;i++)	
	{
		pVar[i].TrimLeft();
		pVar[i].TrimRight();
		if(pVar[i]==_T("")) return FALSE;
		if(IsCharAlpha(pVar[i][0]))//pVar[i]是变量
		{
			int nVarNum=m_VariablePtrList.GetCount();
			POSITION pos=m_VariablePtrList.GetHeadPosition();
			POSITION tippos=NULL;
			for(int j=0;j<nVarNum;j++)
			{
				CString sVarName=pVar[i];
				sVarName.TrimRight("\'");
				sVarName.TrimLeft("~");
				CArrayMatrix * pt=m_VariablePtrList.GetAt(pos);
				if(pt->GetName()==sVarName) {tippos=pos;break;}
				m_VariablePtrList.GetNext(pos);
			}
			if(tippos==NULL) return FALSE;
			else
			{
				CArrayMatrix *pMatrix=new CArrayMatrix;
				*pMatrix=*(m_VariablePtrList.GetAt(tippos));
				//对多次求转置的处理,比如A''''的求值
				{
					int len=lstrlen(pVar[i]);
					int index=len-1;
					if(pVar[i][index]==TCHAR('\''))
					{
						while(pVar[i][index]==TCHAR('\'')&&index>0)
						{
							(*pMatrix)=pMatrix->T();
							index--;
						}
					}
				}
				m_List.AddTail(pMatrix);
			}
		}
		else if(pVar[i][0]==TCHAR('~'))//处理~~~A的值
		{
			int glen=lstrlen(pVar[i]);
			int gnum=0;
			for(int g=0;g<glen&&pVar[i][g]==TCHAR('~');g++) gnum++;
			if(glen==num) return FALSE;
			CString Var=pVar[i].Right(glen-gnum);
			int nVarNum=m_VariablePtrList.GetCount();
			POSITION pos=m_VariablePtrList.GetHeadPosition();
			POSITION tippos=NULL;
			for(int j=0;j<nVarNum;j++)
			{
				CArrayMatrix * pt=m_VariablePtrList.GetAt(pos);
				if(pt->GetName()==Var) {tippos=pos;break;}
				m_VariablePtrList.GetNext(pos);
			}
			if(tippos==NULL) return FALSE;
			else
			{
				CArrayMatrix *pMatrix=new CArrayMatrix;
				*pMatrix=*(m_VariablePtrList.GetAt(tippos));
				int k=gnum%2;
				if(k==1) 
				{
					if(!(*pMatrix).CanContrary()) {delete pMatrix;return FALSE;}
					(*pMatrix)=~(*pMatrix);
				}
				m_List.AddTail(pMatrix);
				
			}
			
		}
		else
		{	
			if(IsCharAlphaNumeric(pVar[i][0])||(IsOperator(pVar[i][0])&&IsCharAlphaNumeric(pVar[i][1])))
			{
				CString sName="hyx=";
				sName=sName+pVar[i];
				sName=sName+";";
				CArrayMatrix * Ptr=new CArrayMatrix;
				if(!Ptr->ProcessInput(sName)) {delete Ptr;return FALSE;}
				m_List.AddTail(Ptr);
			}
			else return FALSE;	
		}
	}
	return TRUE;
}
Esempio n. 22
0
int CMatrixDoc::GetVariableNum(const CString &m,CString * & pVar)
{
	pVar=NULL;
	int CharNum=0;
	bool bSign=true;
	int num=0;
	int len=lstrlen(m);
	{
		for(int pos=0;pos<len;pos++)
		{
			if(IsCharAlpha(m[pos])) CharNum++;
		}
	}
	if(CharNum==0)
	{
		pVar=new CString[1];
		*pVar=m;
		pVar->TrimLeft();
		pVar->TrimRight();
		return 1;
	}
	for(int i=0;i<len;i++)
	{
		if(!IsOperator(m[i]))
		{
			if(bSign)
			{
				num++;
				bSign=false;
			}
			else continue;
		}
		else bSign=true;
	}
	if(num==0) return num;
	else
	{
		int tpnum=0;
		pVar=new CString[num];
		CString temp;
		int slen=0;
		bSign=true;
		for(int i=0;i<len;i++)
		{
			if(!IsOperator(m[i]))
			{
				if(bSign)
				{
					tpnum++;
					if(tpnum==num)
					{
						int j=i;
						int number=0;
						CString stp;
						while(j<len&&!IsOperator(m[i]))
						{
							stp.GetBufferSetLength(number+1);
							stp.SetAt(number,m[j]);
							number++;
							j++;
						}
						pVar[num-1]=stp;
					}
					else if(tpnum>1)
					{
						pVar[tpnum-1]=temp;
					}
					temp=_T("");
					slen=1;
					temp.GetBufferSetLength(slen);
					temp.SetAt(0,m[i]);
					if(i<len-1&&IsOperator(m[i+1])) pVar[tpnum-1]=temp;
					bSign=false;
				}
				else
				{
					slen++;
					temp.GetBufferSetLength(slen);
					temp.SetAt(slen-1,m[i]);
				}
			}
			else bSign=true;
		}
	}
	return num;
}
Esempio n. 23
0
static BOOL ConvertTextToTime(PSYSTEMTIME pSt, LPCTSTR szDateTimeStr, LPTSTR szTimeFormat)
{
    SYSTEMTIME st = {0};
    LPTSTR szEndChar;
    DWORD dwTokenLength;
    DWORD dwToken;
    WORD wHourModifier = 0;             // 0 or 12, depends on AM/PM string
    BOOL bHourConverted = FALSE;
    BOOL bMinuteConverted = FALSE;
    BOOL bSecondConverted = FALSE;
    BOOL b12HourFormat = FALSE;
    BOOL bAmPmFound = FALSE;
    int nLength;

    // Remove any leading spaces from szDateTimeStr
    while(*szDateTimeStr == _T(' '))
        szDateTimeStr++;

    while(*szTimeFormat != 0 && *szDateTimeStr != 0)
    {
        // Skip spaces
        while(szDateTimeStr[0] == _T(' '))
            szDateTimeStr++;
        while(szTimeFormat[0] == _T(' '))
            szTimeFormat++;

        dwToken = GetDateFormatToken(szTimeFormat, &dwTokenLength);
        switch(dwToken)
        {
            // "h": Hours with no leading zero for single-digit hours; 12-hour clock.
            // "hh" : Hours with leading zero for single-digit hours; 12-hour clock.
            case 'h':
            case 'hh':
            {
                // Store day number to SYSTEMTIME structure
                st.wHour = (WORD)StrToInt(szDateTimeStr, &szEndChar, 10);
                if(IsCharAlpha(szEndChar[0]) || st.wHour > 12)
                    return FALSE;

                b12HourFormat = TRUE;
                szDateTimeStr = szEndChar;
                szTimeFormat += dwTokenLength;
                break;
            }

            // "H": Hours with no leading zero for single-digit hours; 24-hour clock.
            // "HH": Hours with leading zero for single-digit hours; 24-hour clock.
            case 'H':
            case 'HH':
            {
                // Store day number to SYSTEMTIME structure
                st.wHour = (WORD)StrToInt(szDateTimeStr, &szEndChar, 10);
                if(IsCharAlpha(szEndChar[0]) || st.wHour > 23)
                    return FALSE;

                bHourConverted = TRUE;
                szDateTimeStr = szEndChar;
                szTimeFormat += dwTokenLength;
                break;
            }

            // "m": Minutes with no leading zero for single-digit minutes.
            // "mm": Minutes with leading zero for single-digit minutes.
            case 'm':
            case 'mm':
            {
                // Store day number to SYSTEMTIME structure
                st.wMinute = (WORD)StrToInt(szDateTimeStr, &szEndChar, 10);
                if(IsCharAlpha(szEndChar[0]) || st.wMinute > 59)
                    return FALSE;

                bMinuteConverted = TRUE;
                szDateTimeStr = szEndChar;
                szTimeFormat += dwTokenLength;
                break;
            }


            // "s": Seconds with no leading zero for single-digit seconds.
            // "ss": Seconds with leading zero for single-digit seconds.
            case 's':
            case 'ss':
            {
                // Store day number to SYSTEMTIME structure
                st.wSecond = (WORD)StrToInt(szDateTimeStr, &szEndChar, 10);
                if(IsCharAlpha(szEndChar[0]) || st.wSecond > 59)
                    return FALSE;

                bSecondConverted = TRUE;
                szDateTimeStr = szEndChar;
                szTimeFormat += dwTokenLength;
                break;
            }

            // "t": One character time-marker string, such as A or P.
            // "tt": Multicharacter time-marker string, such as AM or PM.
            case 't':
            case 'tt':
            {
                // Try to recognize the string
                if(AmPmNameToWord(szDateTimeStr, wHourModifier, nLength) == FALSE)
                    return FALSE;

                bAmPmFound = TRUE;
                szDateTimeStr += nLength;
                szTimeFormat += dwTokenLength;
                break;
            }

            // All other chars are considered unexpected
            default:
                return FALSE;
        }

        // Skip equal characters
        while(szDateTimeStr[0] != 0 && szDateTimeStr[0] == szTimeFormat[0])
        {
            szDateTimeStr++;
            szTimeFormat++;
        }

        // If both 12-hour and AM/PM string have been found,
        // consider hour as converted
        if(bHourConverted == FALSE && b12HourFormat && bAmPmFound)
        {
            st.wHour = st.wHour + wHourModifier;
            bHourConverted = TRUE;
        }
    }

    // If all three (hour-minute-second) were converted, we're done
    if(bHourConverted && bMinuteConverted && bSecondConverted)
    {
        pSt->wHour = st.wHour;
        pSt->wMinute = st.wMinute;
        pSt->wSecond = st.wSecond;
        return TRUE;
    }

    // If only hour and minute have been converted, it's OK
    if(bHourConverted && bMinuteConverted && bSecondConverted == FALSE)
    {
        pSt->wHour = st.wHour;
        pSt->wMinute = st.wMinute;
        pSt->wSecond = 0;
        return TRUE;
    }

    // If time is not present at all, we consider this as OK
    if(bHourConverted == FALSE && bMinuteConverted == FALSE && bSecondConverted == FALSE )
    {
        pSt->wHour = 0;
        pSt->wMinute = 0;
        pSt->wSecond = 0;
        return TRUE;
    }

    return FALSE;
}
Esempio n. 24
0
static BOOL ConvertTextToDate(PSYSTEMTIME pSt, LPCTSTR szDateTimeStr, LPTSTR szDateFormat)
{
    SYSTEMTIME st = {0};
    LPTSTR szEndChar;
    DWORD dwTokenLength;
    DWORD dwToken;
    BOOL bMonthConverted = FALSE;
    BOOL bYearConverted = FALSE;
    BOOL bDayConverted = FALSE;
    WORD wDummy;
    int nLength;

    // Remove any leading spaces from szDateTimeStr
    while(*szDateTimeStr == _T(' '))
        szDateTimeStr++;

    while(*szDateFormat != 0 && *szDateTimeStr != 0)
    {
        // Skip spaces
        while(szDateTimeStr[0] == _T(' '))
            szDateTimeStr++;
        while(szDateFormat[0] == _T(' '))
            szDateFormat++;

        dwToken = GetDateFormatToken(szDateFormat, &dwTokenLength);
        switch(dwToken)
        {
            // "d": Day of month as digits with no leading zero for single-digit days. 
            // "dd" : Day of month as digits with leading zero for single-digit days.
            case 'd':
            case 'dd':
            {
                // Day must not be there yet
                if(bDayConverted)
                    return FALSE;

                // Store day number to SYSTEMTIME structure
                st.wDay = (WORD)StrToInt(szDateTimeStr, &szEndChar, 10);
                if(IsCharAlpha(szEndChar[0]) || st.wDay == 0 || st.wDay > 31)
                    return FALSE;

                szDateTimeStr = szEndChar;
                szDateFormat += dwTokenLength;
                bDayConverted = TRUE;
                break;
            }

            // "ddd": Day of week as a three-letter abbreviation (LOCALE_SABBREVDAYNAME)
            // "dddd": Day of week as its full name (LOCALE_SDAYNAME).
            case 'ddd':
            case 'dddd':
            {
                // Convert the day of week. However, ignore the result of the conversion,
                // as day of week is not necessary to get the FILETIME and would require
                // the user to enter correct day of week
                wDummy = LocaleNameToNumber(szDateTimeStr, LOCALE_SDAYNAME1, LOCALE_SDAYNAME7, 0, &nLength);
                if(wDummy == 0xFFFF)
                    return FALSE;

                szDateFormat  += dwTokenLength;
                szDateTimeStr += nLength;
                break;
            }

            // "M": Month as digits with no leading zero for single-digit months.
            // "MM": Month as digits with leading zero for single-digit months.
            // "MMM": Month as a three-letter abbreviation. The function
            //        uses the LOCALE_SABBREVMONTHNAME value associated with the specified locale. 
            // "MMMM": Month as its full name. The function uses the LOCALE_SMONTHNAME
            //         value associated with the specified locale. 
            case 'M':
            case 'MM':
            case 'MMM':
            case 'MMMM':
            {
                // Month must not be there yet
                if(bMonthConverted)
                    return FALSE;

                // Try to convert it from genitive
                st.wMonth = MonthNameGenitiveToNumber(szDateTimeStr, &nLength);
                if(1 <= st.wMonth && st.wMonth <= 13)
                {
                    szDateFormat  += dwTokenLength;
                    szDateTimeStr += nLength;
                    bMonthConverted = TRUE;
                    break;
                }

                // Try to convert it from nominative of the full name
                st.wMonth = LocaleNameToNumber(szDateTimeStr, LOCALE_SMONTHNAME1, LOCALE_SMONTHNAME12, LOCALE_SMONTHNAME13, &nLength);
                if(1 <= st.wMonth && st.wMonth <= 13)
                {
                    szDateFormat  += dwTokenLength;
                    szDateTimeStr += nLength;
                    bMonthConverted = TRUE;
                    break;
                }

                // Try to convert it from the short name
                st.wMonth = LocaleNameToNumber(szDateTimeStr, LOCALE_SABBREVMONTHNAME1, LOCALE_SABBREVMONTHNAME12, LOCALE_SABBREVMONTHNAME13, &nLength);
                if(1 <= st.wMonth && st.wMonth <= 13)
                {
                    szDateFormat  += dwTokenLength;
                    szDateTimeStr += nLength;
                    bMonthConverted = TRUE;
                    break;
                }

                // Try to convert it from the number
                st.wMonth = (WORD)StrToInt(szDateTimeStr, &szEndChar, 10);
                if(IsCharAlpha(szEndChar[0]) || st.wMonth == 0 || st.wMonth > 12)
                    return FALSE;
                
                szDateFormat += dwTokenLength;
                szDateTimeStr = szEndChar;
                bMonthConverted = TRUE;
                break;
            }

            // "y": Year as last two digits, but with no leading zero for years less than 10.
            // "yy": Year as last two digits, but with leading zero for years less than 10.
            // "yyy": Invalid year, but we accept it
            // "yyyy": Year represented by full four digits.
            case 'y':
            case 'yy':
            case 'yyy':
            case 'yyyy':
            {
                // Convert year as digit
                st.wYear = (WORD)StrToInt(szDateTimeStr, &szEndChar, 10);
                if(IsCharAlpha(szEndChar[0]))
                    return FALSE;
                
                // Respect 2-digit years
                if(dwTokenLength == 1 || dwTokenLength == 2)
                {
                    if(80 <= st.wYear && st.wYear < 100)
                        st.wYear += 1900;
                    else
                        st.wYear += 2000;
                }

                // We don't accept years less than 1600
                if(st.wYear < 1600)
                    return FALSE;
                bYearConverted = TRUE;
                szDateTimeStr = szEndChar;
                szDateFormat += dwTokenLength;
                break;
            }

            // All other chars are considered unexpected
            default:
                return FALSE;
        }

        // Skip equal characters
        while(szDateTimeStr[0] != 0 && szDateTimeStr[0] == szDateFormat[0])
        {
            szDateTimeStr++;
            szDateFormat++;
        }
    }

    // If all three (day-month-year) were converted, we're done
    if(bDayConverted && bMonthConverted && bYearConverted)
    {
        szTempDateTime = szDateTimeStr;
        pSt->wDay = st.wDay;
        pSt->wMonth = st.wMonth;
        pSt->wYear = st.wYear;
        return TRUE;
    }

    return FALSE;
}
Esempio n. 25
0
inline int IsAlpha(wchar_t Ch) { return IsCharAlpha(Ch); }
Esempio n. 26
0
inline Boolean IsAnsiAlpha (char c) {return (IsCharAlpha (c));}