Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "SqlNameEdit.hxx"
21 : namespace dbaui
22 : {
23 : //------------------------------------------------------------------
24 0 : sal_Bool isCharOk(sal_Unicode _cChar,sal_Bool _bFirstChar,sal_Bool _bUpperCase,const OUString& _sAllowedChars)
25 : {
26 : return (
27 0 : (_cChar >= 'A' && _cChar <= 'Z') ||
28 0 : _cChar == '_' ||
29 0 : _sAllowedChars.indexOf(_cChar) != -1 ||
30 0 : (!_bFirstChar && (_cChar >= '0' && _cChar <= '9')) ||
31 0 : (!_bUpperCase && (_cChar >= 'a' && _cChar <= 'z'))
32 0 : );
33 : }
34 : //------------------------------------------------------------------
35 0 : sal_Bool OSQLNameChecker::checkString(const OUString& _sToCheck,
36 : OUString& _rsCorrected)
37 : {
38 0 : sal_Bool bCorrected = sal_False;
39 0 : if ( m_bCheck )
40 : {
41 0 : XubString sText = _sToCheck;
42 0 : xub_StrLen nMatch = 0;
43 0 : for ( xub_StrLen i=nMatch;i < sText.Len(); ++i )
44 : {
45 0 : if ( !isCharOk( sText.GetBuffer()[i], i == 0, m_bOnlyUpperCase, m_sAllowedChars ) )
46 : {
47 0 : _rsCorrected += sText.Copy( nMatch, i - nMatch );
48 0 : bCorrected = sal_True;
49 0 : nMatch = i + 1;
50 : }
51 : }
52 0 : _rsCorrected += sText.Copy( nMatch, sText.Len() - nMatch );
53 : }
54 0 : return bCorrected;
55 : }
56 : //------------------------------------------------------------------
57 0 : void OSQLNameEdit::Modify()
58 : {
59 0 : OUString sCorrected;
60 0 : if ( checkString( GetText(),sCorrected ) )
61 : {
62 0 : Selection aSel = GetSelection();
63 0 : aSel.setMax( aSel.getMin() );
64 0 : SetText( sCorrected, aSel );
65 :
66 0 : SaveValue();
67 : }
68 0 : Edit::Modify();
69 0 : }
70 : //------------------------------------------------------------------
71 0 : void OSQLNameComboBox::Modify()
72 : {
73 0 : OUString sCorrected;
74 0 : if ( checkString( GetText(),sCorrected ) )
75 : {
76 0 : Selection aSel = GetSelection();
77 0 : aSel.setMax( aSel.getMin() );
78 0 : SetText( sCorrected );
79 :
80 0 : SaveValue();
81 : }
82 0 : ComboBox::Modify();
83 0 : }
84 12 : }
85 : // -----------------------------------------------------------------------------
86 :
87 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|