/* --------------------------------------------------------- Project activething Active Thing (activething.com) git.activething.com/go File name char_atts.go Created by DEV Modified 23/10/2023 Copyright 2023 activething.com --------------------------------------------------------- // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // */ package chars type CharAtts [maxTableSize]CharAtt func (t *CharAtts) SetRange(att CharAtt, begin, end int) { if end >= maxTableSize { end = maxTableSize - 1 } for ix := begin; ix <= end; ix++ { t[ix] = att } } func (t *CharAtts) AddRange(att CharAtt, begin, end int) { if end >= maxTableSize { end = maxTableSize - 1 } for ix := begin; ix <= end; ix++ { t[ix] |= att } } func (t *CharAtts) DelRange(att CharAtt, begin, end int) { if end >= maxTableSize { end = maxTableSize - 1 } for ix := begin; ix <= end; ix++ { t[ix] &^= att } } func (t *CharAtts) SetSlice(list []byte, att CharAtt, opr int) { for _, bt := range list { t[bt] = att } } func (t *CharAtts) AddSlice(list []byte, att CharAtt) { for _, bt := range list { t[bt] |= att } } func (t *CharAtts) DelSlice(list []byte, att CharAtt, opr int) { for _, bt := range list { t[bt] &^= att } } func (t CharAtts) Has(source []byte, att CharAtt) bool { for _, ch := range source { if t[ch]&att == att { return true } } return false } func (t CharAtts) HasAny(source []byte, att CharAtt) bool { for _, ch := range source { if t[ch]&att != 0 { return true } } return false } func (t CharAtts) IsOf(source []byte, att CharAtt) bool { if len(source) == 0 { return false } for _, ch := range source { if t[ch]&att != att { return false } } return true } func (t CharAtts) IsOfAny(source []byte, att CharAtt) bool { if len(source) == 0 { return false } for _, ch := range source { if t[ch]&att == 0 { return false } } return true } /* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA. "LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS. SIDDHARTA - HERMANN HESSE - ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */