android: Update app icon to new startcenter icon
[LibreOffice.git] / dbaccess / source / ui / control / SqlNameEdit.cxx
blob9ac58cfda851bcc47e0b188fa1f5ef430afc10ba
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>
22 namespace dbaui
24 static bool isCharOk(sal_Unicode _cChar,bool _bFirstChar, std::u16string_view _sAllowedChars)
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')
34 bool OSQLNameChecker::checkString(std::u16string_view _sToCheck,
35 OUString& _rsCorrected)
37 bool bCorrected = false;
38 if ( m_bCheck )
40 sal_Int32 nMatch = 0;
41 for (size_t i = nMatch; i < _sToCheck.size(); ++i)
43 if ( !isCharOk( _sToCheck[i], i == 0, m_sAllowedChars ) )
45 _rsCorrected += _sToCheck.substr(nMatch, i - nMatch);
46 bCorrected = true;
47 nMatch = i + 1;
50 _rsCorrected += _sToCheck.substr( nMatch );
52 return bCorrected;
55 namespace
57 void checkName(OSQLNameChecker& rChecker, weld::Entry& rEntry)
59 OUString sCorrected;
60 if (rChecker.checkString(rEntry.get_text(), sCorrected))
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);
68 rEntry.save_value();
73 IMPL_LINK(OSQLNameEditControl, ModifyHdl, weld::Entry&, rEntry, void)
75 checkName(*this, rEntry);
76 m_ChainChangedHdl.Call(rEntry);
79 IMPL_LINK(OSQLNameEntry, ModifyHdl, weld::Entry&, rEntry, void)
81 checkName(*this, rEntry);
85 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */