LibreOffice Module dbaccess (master)
1
dbaccess
source
ui
control
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
22
namespace
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: */
SqlNameEdit.hxx
dbaui::OSQLNameChecker
Definition:
SqlNameEdit.hxx:28
dbaui::OSQLNameChecker::checkString
bool checkString(std::u16string_view _sToCheck, OUString &_rsCorrected)
Definition:
SqlNameEdit.cxx:34
dbaui::OSQLNameChecker::m_sAllowedChars
OUString m_sAllowedChars
Definition:
SqlNameEdit.hxx:29
dbaui::OSQLNameChecker::m_bCheck
bool m_bCheck
Definition:
SqlNameEdit.hxx:30
dbaui::OSQLNameEditControl
Definition:
SqlNameEdit.hxx:51
dbaui::OSQLNameEntry
Definition:
SqlNameEdit.hxx:95
weld::Entry
weld::Entry::select_region
virtual void select_region(int nStartPos, int nEndPos)=0
weld::Entry::set_text
virtual void set_text(const OUString &rText)=0
weld::Entry::save_value
void save_value()
weld::Entry::get_selection_bounds
virtual bool get_selection_bounds(int &rStartPos, int &rEndPos)=0
weld::Entry::get_text
virtual OUString get_text() const=0
dbaui
dbaui::IMPL_LINK
IMPL_LINK(OApplicationController, OnSelectContainer, void *, _pType, void)
Definition:
AppController.cxx:1850
dbaui::isCharOk
static bool isCharOk(sal_Unicode _cChar, bool _bFirstChar, std::u16string_view _sAllowedChars)
Definition:
SqlNameEdit.cxx:24
i
int i
sal_Unicode
sal_uInt16 sal_Unicode
Generated on Sun Jul 30 2023 04:30:16 for LibreOffice Module dbaccess (master) by
1.9.3