1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaccess.hxx"
26 #ifndef DBAUI_SQLNAMEEDIT_HXX
27 #include "SqlNameEdit.hxx"
28 #endif
29 namespace dbaui
30 {
31 	//------------------------------------------------------------------
32 	sal_Bool isCharOk(sal_Unicode _cChar,sal_Bool _bFirstChar,sal_Bool _bUpperCase,const ::rtl::OUString& _sAllowedChars)
33 	{
34 		return	(
35                  (_cChar >= 'A' && _cChar <= 'Z') ||
36                  _cChar == '_' ||
37                  _sAllowedChars.indexOf(_cChar) != -1 ||
38                  (!_bFirstChar && (_cChar >= '0' && _cChar <= '9')) ||
39                  (!_bUpperCase && (_cChar >= 'a' && _cChar <= 'z'))
40                 );
41 	}
42 	//------------------------------------------------------------------
43 	sal_Bool OSQLNameChecker::checkString(	const ::rtl::OUString& _sOldValue,
44 										const ::rtl::OUString& _sToCheck,
45 										::rtl::OUString& _rsCorrected)
46 	{
47 		sal_Bool bCorrected = sal_False;
48 		if ( m_bCheck )
49 		{
50 			XubString sSavedValue	= _sOldValue;
51 			XubString sText			= _sToCheck;
52 			xub_StrLen nMatch		= 0;
53 			for ( xub_StrLen i=nMatch;i < sText.Len(); ++i )
54 			{
55 				if ( !isCharOk( sText.GetBuffer()[i], i == 0, m_bOnlyUpperCase, m_sAllowedChars ) )
56 				{
57 					_rsCorrected += sText.Copy( nMatch, i - nMatch );
58 					bCorrected = sal_True;
59 					nMatch = i + 1;
60 				}
61 			}
62 			_rsCorrected += sText.Copy( nMatch, sText.Len() - nMatch );
63 		}
64 		return bCorrected;
65 	}
66 	//------------------------------------------------------------------
67 	void OSQLNameEdit::Modify()
68 	{
69 		::rtl::OUString sCorrected;
70 		if ( checkString( GetSavedValue(),GetText(),sCorrected ) )
71 		{
72 			Selection aSel = GetSelection();
73 			aSel.setMax( aSel.getMin() );
74 			SetText( sCorrected, aSel );
75 
76 			SaveValue();
77 		}
78 		Edit::Modify();
79 	}
80 	//------------------------------------------------------------------
81 	void OSQLNameComboBox::Modify()
82 	{
83 		::rtl::OUString sCorrected;
84 		if ( checkString( GetSavedValue(),GetText(),sCorrected ) )
85 		{
86 			Selection aSel = GetSelection();
87 			aSel.setMax( aSel.getMin() );
88 			SetText( sCorrected );
89 
90 			SaveValue();
91 		}
92 		ComboBox::Modify();
93 	}
94 }
95 // -----------------------------------------------------------------------------
96 
97