LibreOffice Module dbaccess (master) 1
SqlNameEdit.cxx
Go to the documentation of this file.
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
22namespace dbaui
23{
24 static bool isCharOk(sal_Unicode _cChar,bool _bFirstChar, std::u16string_view _sAllowedChars)
25 {
26 return (
27 (_cChar >= 'A' && _cChar <= 'Z') ||
28 _cChar == '_' ||
29 _sAllowedChars.find(_cChar) != std::u16string_view::npos ||
30 (!_bFirstChar && (_cChar >= '0' && _cChar <= '9')) ||
31 (_cChar >= 'a' && _cChar <= 'z')
32 );
33 }
34 bool OSQLNameChecker::checkString(std::u16string_view _sToCheck,
35 OUString& _rsCorrected)
36 {
37 bool bCorrected = false;
38 if ( m_bCheck )
39 {
40 sal_Int32 nMatch = 0;
41 for (size_t i = nMatch; i < _sToCheck.size(); ++i)
42 {
43 if ( !isCharOk( _sToCheck[i], i == 0, m_sAllowedChars ) )
44 {
45 _rsCorrected += _sToCheck.substr(nMatch, i - nMatch);
46 bCorrected = true;
47 nMatch = i + 1;
48 }
49 }
50 _rsCorrected += _sToCheck.substr( nMatch );
51 }
52 return bCorrected;
53 }
54
55 namespace
56 {
57 void checkName(OSQLNameChecker& rChecker, weld::Entry& rEntry)
58 {
59 OUString sCorrected;
60 if (rChecker.checkString(rEntry.get_text(), sCorrected))
61 {
62 int nStartPos, nEndPos;
63 rEntry.get_selection_bounds(nStartPos, nEndPos);
64 int nMin = std::min(nStartPos, nEndPos);
65 rEntry.set_text(sCorrected);
66 rEntry.select_region(nMin, nMin);
67
68 rEntry.save_value();
69 }
70 }
71 }
72
73 IMPL_LINK(OSQLNameEditControl, ModifyHdl, weld::Entry&, rEntry, void)
74 {
75 checkName(*this, rEntry);
76 m_ChainChangedHdl.Call(rEntry);
77 }
78
79 IMPL_LINK(OSQLNameEntry, ModifyHdl, weld::Entry&, rEntry, void)
80 {
81 checkName(*this, rEntry);
82 }
83}
84
85/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool checkString(std::u16string_view _sToCheck, OUString &_rsCorrected)
Definition: SqlNameEdit.cxx:34
virtual void select_region(int nStartPos, int nEndPos)=0
virtual void set_text(const OUString &rText)=0
void save_value()
virtual bool get_selection_bounds(int &rStartPos, int &rEndPos)=0
virtual OUString get_text() const=0
IMPL_LINK(OApplicationController, OnSelectContainer, void *, _pType, void)
static bool isCharOk(sal_Unicode _cChar, bool _bFirstChar, std::u16string_view _sAllowedChars)
Definition: SqlNameEdit.cxx:24
int i
sal_uInt16 sal_Unicode