Branch data 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 ::rtl::OUString& _sAllowedChars)
25 : : {
26 : : return (
27 : : (_cChar >= 'A' && _cChar <= 'Z') ||
28 : : _cChar == '_' ||
29 : 0 : _sAllowedChars.indexOf(_cChar) != -1 ||
30 : : (!_bFirstChar && (_cChar >= '0' && _cChar <= '9')) ||
31 : : (!_bUpperCase && (_cChar >= 'a' && _cChar <= 'z'))
32 [ # # ][ # # ]: 0 : );
[ # # # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
33 : : }
34 : : //------------------------------------------------------------------
35 : 0 : sal_Bool OSQLNameChecker::checkString( const ::rtl::OUString& _sOldValue,
36 : : const ::rtl::OUString& _sToCheck,
37 : : ::rtl::OUString& _rsCorrected)
38 : : {
39 : 0 : sal_Bool bCorrected = sal_False;
40 [ # # ]: 0 : if ( m_bCheck )
41 : : {
42 [ # # ]: 0 : XubString sSavedValue = _sOldValue;
43 [ # # ]: 0 : XubString sText = _sToCheck;
44 : 0 : xub_StrLen nMatch = 0;
45 [ # # ]: 0 : for ( xub_StrLen i=nMatch;i < sText.Len(); ++i )
46 : : {
47 [ # # ]: 0 : if ( !isCharOk( sText.GetBuffer()[i], i == 0, m_bOnlyUpperCase, m_sAllowedChars ) )
48 : : {
49 [ # # ][ # # ]: 0 : _rsCorrected += sText.Copy( nMatch, i - nMatch );
[ # # ]
50 : 0 : bCorrected = sal_True;
51 : 0 : nMatch = i + 1;
52 : : }
53 : : }
54 [ # # ][ # # ]: 0 : _rsCorrected += sText.Copy( nMatch, sText.Len() - nMatch );
[ # # ][ # # ]
[ # # ]
55 : : }
56 : 0 : return bCorrected;
57 : : }
58 : : //------------------------------------------------------------------
59 : 0 : void OSQLNameEdit::Modify()
60 : : {
61 : 0 : ::rtl::OUString sCorrected;
62 [ # # ][ # # ]: 0 : if ( checkString( GetSavedValue(),GetText(),sCorrected ) )
[ # # ][ # # ]
[ # # ][ # # ]
63 : : {
64 [ # # ]: 0 : Selection aSel = GetSelection();
65 : 0 : aSel.setMax( aSel.getMin() );
66 [ # # ][ # # ]: 0 : SetText( sCorrected, aSel );
[ # # ]
67 : :
68 [ # # ]: 0 : SaveValue();
69 : : }
70 [ # # ]: 0 : Edit::Modify();
71 : 0 : }
72 : : //------------------------------------------------------------------
73 : 0 : void OSQLNameComboBox::Modify()
74 : : {
75 : 0 : ::rtl::OUString sCorrected;
76 [ # # ][ # # ]: 0 : if ( checkString( GetSavedValue(),GetText(),sCorrected ) )
[ # # ][ # # ]
[ # # ][ # # ]
77 : : {
78 [ # # ]: 0 : Selection aSel = GetSelection();
79 : 0 : aSel.setMax( aSel.getMin() );
80 [ # # ][ # # ]: 0 : SetText( sCorrected );
[ # # ]
81 : :
82 [ # # ]: 0 : SaveValue();
83 : : }
84 [ # # ]: 0 : ComboBox::Modify();
85 : 0 : }
86 : : }
87 : : // -----------------------------------------------------------------------------
88 : :
89 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|