1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef ADABASUI_SQLNAMEEDIT_HXX 25 #include "ASQLNameEdit.hxx" 26 #endif 27 namespace adabasui 28 { 29 //------------------------------------------------------------------ isCharOk(sal_Unicode _cChar)30 sal_Bool isCharOk(sal_Unicode _cChar) 31 { 32 return ( 33 (_cChar >= 'A' && _cChar <= 'Z') || 34 _cChar == '_' || 35 ((_cChar >= '0' && _cChar <= '9')) || 36 ((_cChar >= 'a' && _cChar <= 'z')) 37 ); 38 } 39 //------------------------------------------------------------------ checkString(const::rtl::OUString & _sOldValue,const::rtl::OUString & _sToCheck,::rtl::OUString & _rsCorrected)40 sal_Bool OSQLNameChecker::checkString( const ::rtl::OUString& _sOldValue, 41 const ::rtl::OUString& _sToCheck, 42 ::rtl::OUString& _rsCorrected) 43 { 44 sal_Bool bCorrected = sal_False; 45 XubString sSavedValue = _sOldValue; 46 XubString sText = _sToCheck; 47 xub_StrLen nMatch = 0; 48 for ( xub_StrLen i=nMatch;i < sText.Len(); ++i ) 49 { 50 if ( !isCharOk( sText.GetBuffer()[i]) ) 51 { 52 _rsCorrected += sText.Copy( nMatch, i - nMatch ); 53 bCorrected = sal_True; 54 nMatch = i + 1; 55 } 56 } 57 _rsCorrected += sText.Copy( nMatch, sText.Len() - nMatch ); 58 return bCorrected; 59 } 60 //------------------------------------------------------------------ Modify()61 void OSQLNameEdit::Modify() 62 { 63 ::rtl::OUString sCorrected; 64 if ( checkString( GetSavedValue(),GetText(),sCorrected ) ) 65 { 66 Selection aSel = GetSelection(); 67 aSel.setMax( aSel.getMin() ); 68 SetText( sCorrected, aSel ); 69 70 SaveValue(); 71 } 72 Edit::Modify(); 73 } 74 } 75 // ----------------------------------------------------------------------------- 76 77