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: ASqlNameEdit.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 #ifndef ADABASUI_SQLNAMEEDIT_HXX
32 #include "ASQLNameEdit.hxx"
36 //------------------------------------------------------------------
37 sal_Bool
isCharOk(sal_Unicode _cChar
)
40 (_cChar
>= 'A' && _cChar
<= 'Z') ||
42 ((_cChar
>= '0' && _cChar
<= '9')) ||
43 ((_cChar
>= 'a' && _cChar
<= 'z'))
46 //------------------------------------------------------------------
47 sal_Bool
OSQLNameChecker::checkString( const ::rtl::OUString
& _sOldValue
,
48 const ::rtl::OUString
& _sToCheck
,
49 ::rtl::OUString
& _rsCorrected
)
51 sal_Bool bCorrected
= sal_False
;
52 XubString sSavedValue
= _sOldValue
;
53 XubString sText
= _sToCheck
;
54 xub_StrLen nMatch
= 0;
55 for ( xub_StrLen i
=nMatch
;i
< sText
.Len(); ++i
)
57 if ( !isCharOk( sText
.GetBuffer()[i
]) )
59 _rsCorrected
+= sText
.Copy( nMatch
, i
- nMatch
);
60 bCorrected
= sal_True
;
64 _rsCorrected
+= sText
.Copy( nMatch
, sText
.Len() - nMatch
);
67 //------------------------------------------------------------------
68 void OSQLNameEdit::Modify()
70 ::rtl::OUString sCorrected
;
71 if ( checkString( GetSavedValue(),GetText(),sCorrected
) )
73 Selection aSel
= GetSelection();
74 aSel
.setMax( aSel
.getMin() );
75 SetText( sCorrected
, aSel
);
82 // -----------------------------------------------------------------------------