1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "SqlNameEdit.hxx"
21 #include <vcl/builderfactory.hxx>
25 bool isCharOk(sal_Unicode _cChar
,bool _bFirstChar
,bool _bUpperCase
,const OUString
& _sAllowedChars
)
28 (_cChar
>= 'A' && _cChar
<= 'Z') ||
30 _sAllowedChars
.indexOf(_cChar
) != -1 ||
31 (!_bFirstChar
&& (_cChar
>= '0' && _cChar
<= '9')) ||
32 (!_bUpperCase
&& (_cChar
>= 'a' && _cChar
<= 'z'))
35 bool OSQLNameChecker::checkString(const OUString
& _sToCheck
,
36 OUString
& _rsCorrected
)
38 bool bCorrected
= false;
41 OUString sText
= _sToCheck
;
43 for (sal_Int32 i
= nMatch
; i
< sText
.getLength(); ++i
)
45 if ( !isCharOk( sText
[i
], i
== 0, m_bOnlyUpperCase
, m_sAllowedChars
) )
47 _rsCorrected
+= sText
.copy(nMatch
, i
- nMatch
);
52 _rsCorrected
+= sText
.copy( nMatch
, sText
.getLength() - nMatch
);
56 void OSQLNameEdit::Modify()
59 if ( checkString( GetText(),sCorrected
) )
61 Selection aSel
= GetSelection();
62 aSel
.setMax( aSel
.getMin() );
63 SetText( sCorrected
, aSel
);
69 void OSQLNameComboBox::Modify()
72 if ( checkString( GetText(),sCorrected
) )
74 Selection aSel
= GetSelection();
75 aSel
.setMax( aSel
.getMin() );
76 SetText( sCorrected
);
84 using namespace dbaui
;
86 VCL_BUILDER_FACTORY(OSQLNameEdit
)
87 VCL_BUILDER_FACTORY(OSQLNameComboBox
)
89 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */