1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SqlNameEdit.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBAUI_SQLNAMEEDIT_HXX
34 #include "SqlNameEdit.hxx"
38 //------------------------------------------------------------------
39 sal_Bool
isCharOk(sal_Unicode _cChar
,sal_Bool _bFirstChar
,sal_Bool _bUpperCase
,const ::rtl::OUString
& _sAllowedChars
)
42 (_cChar
>= 'A' && _cChar
<= 'Z') ||
44 _sAllowedChars
.indexOf(_cChar
) != -1 ||
45 (!_bFirstChar
&& (_cChar
>= '0' && _cChar
<= '9')) ||
46 (!_bUpperCase
&& (_cChar
>= 'a' && _cChar
<= 'z'))
49 //------------------------------------------------------------------
50 sal_Bool
OSQLNameChecker::checkString( const ::rtl::OUString
& _sOldValue
,
51 const ::rtl::OUString
& _sToCheck
,
52 ::rtl::OUString
& _rsCorrected
)
54 sal_Bool bCorrected
= sal_False
;
57 XubString sSavedValue
= _sOldValue
;
58 XubString sText
= _sToCheck
;
59 xub_StrLen nMatch
= 0;
60 for ( xub_StrLen i
=nMatch
;i
< sText
.Len(); ++i
)
62 if ( !isCharOk( sText
.GetBuffer()[i
], i
== 0, m_bOnlyUpperCase
, m_sAllowedChars
) )
64 _rsCorrected
+= sText
.Copy( nMatch
, i
- nMatch
);
65 bCorrected
= sal_True
;
69 _rsCorrected
+= sText
.Copy( nMatch
, sText
.Len() - nMatch
);
73 //------------------------------------------------------------------
74 void OSQLNameEdit::Modify()
76 ::rtl::OUString sCorrected
;
77 if ( checkString( GetSavedValue(),GetText(),sCorrected
) )
79 Selection aSel
= GetSelection();
80 aSel
.setMax( aSel
.getMin() );
81 SetText( sCorrected
, aSel
);
87 //------------------------------------------------------------------
88 void OSQLNameComboBox::Modify()
90 ::rtl::OUString sCorrected
;
91 if ( checkString( GetSavedValue(),GetText(),sCorrected
) )
93 Selection aSel
= GetSelection();
94 aSel
.setMax( aSel
.getMin() );
95 SetText( sCorrected
);
102 // -----------------------------------------------------------------------------