Bump version to 5.0-14
[LibreOffice.git] / dbaccess / source / ui / control / SqlNameEdit.cxx
blob2816c986624115d4cf7cc63b4f51de59a40fabb1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
23 namespace dbaui
25 bool isCharOk(sal_Unicode _cChar,bool _bFirstChar,bool _bUpperCase,const OUString& _sAllowedChars)
27 return (
28 (_cChar >= 'A' && _cChar <= 'Z') ||
29 _cChar == '_' ||
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;
39 if ( m_bCheck )
41 OUString sText = _sToCheck;
42 sal_Int32 nMatch = 0;
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);
48 bCorrected = true;
49 nMatch = i + 1;
52 _rsCorrected += sText.copy( nMatch, sText.getLength() - nMatch );
54 return bCorrected;
56 void OSQLNameEdit::Modify()
58 OUString sCorrected;
59 if ( checkString( GetText(),sCorrected ) )
61 Selection aSel = GetSelection();
62 aSel.setMax( aSel.getMin() );
63 SetText( sCorrected, aSel );
65 SaveValue();
67 Edit::Modify();
69 void OSQLNameComboBox::Modify()
71 OUString sCorrected;
72 if ( checkString( GetText(),sCorrected ) )
74 Selection aSel = GetSelection();
75 aSel.setMax( aSel.getMin() );
76 SetText( sCorrected );
78 SaveValue();
80 ComboBox::Modify();
84 using namespace dbaui;
86 VCL_BUILDER_FACTORY(OSQLNameEdit)
87 VCL_BUILDER_FACTORY(OSQLNameComboBox)
89 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */