This file is indexed.

/usr/include/kytea/kytea-string.h is in libkytea-dev 0.4.6+dfsg-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
* Copyright 2009, KyTea Development Team
* 
* 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.
*/

// Turn this on to make KyTea do boundary checking (useful for development)
// #define KYTEA_SAFE

#ifndef KYTEA_STRING_H__
#define KYTEA_STRING_H__

#include <vector>
#include <cstddef>
// #include <stdexcept>
// #include <cstring>
// #include <sstream>
// #include <iostream>

namespace kytea {

typedef unsigned short KyteaChar;

class StringUtil;

// an implementation of a string, kept in memory
class KyteaStringImpl {

public:
    unsigned length_;
    unsigned count_;
    KyteaChar* chars_;

    KyteaStringImpl() : length_(0), count_(1), chars_(0) { }
    KyteaStringImpl(unsigned length);
    KyteaStringImpl(const KyteaStringImpl & impl);
    ~KyteaStringImpl() {
        if(chars_)
            delete [] chars_;
    }

    unsigned dec() { return --count_; }
    unsigned inc() { return ++count_; }

};

class KyteaString {

public:
    friend class StringUtil;
    
private:
    KyteaStringImpl* impl_;

public:

    typedef std::vector<KyteaString> Tokens;

    // ctor
    KyteaString() : impl_(0) { }
    KyteaString(const KyteaString & str) { 
        impl_ = str.impl_;
        if(impl_) impl_->inc();
    }
    KyteaString(unsigned length) { impl_ = new KyteaStringImpl(length); }
    
    // dtor
    ~KyteaString() {
        if(impl_ && !impl_->dec())
            delete impl_;
    }

    // tokenize the string using the characters in the delimiter string
    Tokens tokenize(const KyteaString & delim, bool includeDelim = false) const;

    // splice a string into the appropriate location
    void splice(const KyteaString& str, unsigned pos);

    // Get the substring of a KyteaString
    KyteaString substr(unsigned s) const;
    KyteaString substr(unsigned s, unsigned l) const;
    
    inline KyteaChar & operator[](int i) {
#ifdef KYTEA_SAFE
        if(impl_ == 0 || i < 0 || (unsigned)i >= impl_->length_)
            throw std::runtime_error("string index out of bounds");
#endif
        return getImpl()->chars_[i];
    }
    
    inline const KyteaChar & operator[](int i) const {
#ifdef KYTEA_SAFE
        if(impl_ == 0 || i < 0 || (unsigned)i >= impl_->length_)
            throw std::runtime_error("string index out of bounds");
#endif
        return impl_->chars_[i];
    }
    
    KyteaString & operator= (const KyteaString &str) {
        if(impl_ && !impl_->dec())
            delete impl_;
        impl_ = str.impl_;
        if(impl_) impl_->inc();
        return *this;
    }


    inline unsigned length() const {
        return (impl_?impl_->length_:0); 
    }

    // Get the hash for this value
    size_t getHash() const;

    // Get the implementation
    inline const KyteaStringImpl * getImpl() const {
        return impl_;
    } 
    KyteaStringImpl * getImpl();

    // Find if it begins with a particular string
    bool beginsWith(const KyteaString & s) const;

};

inline KyteaString operator+(const KyteaString& a, const KyteaChar& b) {
    const KyteaStringImpl * aimp = a.getImpl();
    if(aimp == 0) {
        KyteaString ret(1);
        ret[0] = b;
        return ret;
    }
    KyteaString ret(aimp->length_+1);
    ret.splice(a,0);
    ret[aimp->length_]=b;
    return ret;
}

inline KyteaString operator+(const KyteaString& a, const KyteaString& b) {
    const KyteaStringImpl * aimp = a.getImpl();
    if(aimp == 0)
        return b;
    const KyteaStringImpl * bimp = b.getImpl();
    if(bimp == 0)
        return a;
    KyteaString ret(aimp->length_+bimp->length_);
    ret.splice(a,0);
    ret.splice(b,aimp->length_);
    return ret;
}

inline bool operator<(const KyteaString & a, const KyteaString & b) {
    unsigned i;
    const unsigned al = a.length(), bl = b.length(), ml=std::min(al,bl);
    for(i = 0; i < ml; i++) {
        if(a[i] < b[i]) return true;
        else if(b[i] < a[i]) return false;
    }
    return (bl != i);
}

inline bool operator==(const KyteaString & a, const KyteaString & b) {
    unsigned i;
    const unsigned al = a.length();
    if(al!=b.length())
        return false;
    for(i = 0; i < al; i++)
        if(a[i] != b[i]) return false;
    return true;
}

inline bool operator!=(const KyteaString & a, const KyteaString & b) {
    return !(a==b);
}


// hashing using the djb2 algorithm
//  found at
//  http://www.cse.yorku.ca/~oz/hash.html
class KyteaStringHash {
public:
    size_t operator()(const KyteaString & x) const {
        return x.getHash();
    }
};

}

#endif