Coverage Report

Created: 2025-11-11 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/logging-log4cxx/src/main/cpp/nameabbreviator.cpp
Line
Count
Source
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
#include <log4cxx/pattern/nameabbreviator.h>
19
#include <log4cxx/helpers/exception.h>
20
#include <log4cxx/helpers/stringhelper.h>
21
#include <log4cxx/helpers/loglog.h>
22
#include <vector>
23
#include <limits.h>
24
#include <stdexcept>
25
26
using namespace LOG4CXX_NS;
27
using namespace LOG4CXX_NS::pattern;
28
using namespace LOG4CXX_NS::helpers;
29
30
IMPLEMENT_LOG4CXX_OBJECT(NameAbbreviator)
31
32
NameAbbreviator::NameAbbreviator()
33
7.95k
{
34
7.95k
}
35
36
NameAbbreviator::~NameAbbreviator()
37
7.95k
{
38
7.95k
}
39
40
namespace LOG4CXX_NS
41
{
42
namespace pattern
43
{
44
/**
45
 * Abbreviator that simply appends full name to buffer.
46
 */
47
class NOPAbbreviator : public NameAbbreviator
48
{
49
  public:
50
    DECLARE_ABSTRACT_LOG4CXX_OBJECT(NOPAbbreviator)
51
0
    BEGIN_LOG4CXX_CAST_MAP()
52
0
    LOG4CXX_CAST_ENTRY(NOPAbbreviator)
53
0
    LOG4CXX_CAST_ENTRY_CHAIN(NameAbbreviator)
54
0
    END_LOG4CXX_CAST_MAP()
55
56
    /**
57
     * Constructor.
58
     */
59
    NOPAbbreviator()
60
4
    {
61
4
    }
62
63
    /**
64
     * {@inheritDoc}
65
     */
66
    void abbreviate(LogString::size_type /* nameStart */, LogString& /* buf */) const override
67
68
    {
68
68
    }
log4cxx::pattern::NOPAbbreviator::abbreviate(unsigned long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) const
Line
Count
Source
67
41
    {
68
41
    }
log4cxx::pattern::NOPAbbreviator::abbreviate(unsigned long, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&) const
Line
Count
Source
67
27
    {
68
27
    }
69
};
70
71
72
/**
73
 * Abbreviator that drops starting path elements.
74
 */
75
class MaxElementAbbreviator : public NameAbbreviator
76
{
77
    /**
78
     * Maximum number of path elements to output.
79
     */
80
    const int count;
81
82
  public:
83
    DECLARE_ABSTRACT_LOG4CXX_OBJECT(MaxElementAbbreviator)
84
0
    BEGIN_LOG4CXX_CAST_MAP()
85
0
    LOG4CXX_CAST_ENTRY(MaxElementAbbreviator)
86
0
    LOG4CXX_CAST_ENTRY_CHAIN(NameAbbreviator)
87
0
    END_LOG4CXX_CAST_MAP()
88
    /**
89
     * Create new instance.
90
     * @param count maximum number of path elements to output.
91
     */
92
3.61k
    MaxElementAbbreviator(const int count1) : count(count1)
93
3.61k
    {
94
3.61k
    }
95
96
    /**
97
     * Abbreviate name.
98
     * @param buf buffer to append abbreviation.
99
     * @param nameStart start of name to abbreviate.
100
     */
101
    void abbreviate(LogString::size_type nameStart, LogString& buf) const override
102
4.53k
    {
103
      // We substract 1 from 'len' when assigning to 'end' to avoid out of
104
      // bounds exception in return r.substring(end+1, len). This can happen if
105
      // precision is 1 and the logger name ends with a dot.
106
4.53k
      LogString::size_type end = buf.length() - 1;
107
108
10.8k
      for (LogString::size_type i = count; i > 0; i--)
109
6.49k
      {
110
6.49k
        end = buf.rfind(0x2E /* '.' */, end - 1);
111
112
6.49k
        if ((end == LogString::npos) || (end < nameStart))
113
229
        {
114
229
          return;
115
229
        }
116
6.49k
      }
117
118
4.30k
      buf.erase(buf.begin() + nameStart, buf.begin() + (end + 1));
119
4.30k
    }
log4cxx::pattern::MaxElementAbbreviator::abbreviate(unsigned long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) const
Line
Count
Source
102
4.32k
    {
103
      // We substract 1 from 'len' when assigning to 'end' to avoid out of
104
      // bounds exception in return r.substring(end+1, len). This can happen if
105
      // precision is 1 and the logger name ends with a dot.
106
4.32k
      LogString::size_type end = buf.length() - 1;
107
108
9.30k
      for (LogString::size_type i = count; i > 0; i--)
109
5.08k
      {
110
5.08k
        end = buf.rfind(0x2E /* '.' */, end - 1);
111
112
5.08k
        if ((end == LogString::npos) || (end < nameStart))
113
107
        {
114
107
          return;
115
107
        }
116
5.08k
      }
117
118
4.21k
      buf.erase(buf.begin() + nameStart, buf.begin() + (end + 1));
119
4.21k
    }
log4cxx::pattern::MaxElementAbbreviator::abbreviate(unsigned long, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&) const
Line
Count
Source
102
213
    {
103
      // We substract 1 from 'len' when assigning to 'end' to avoid out of
104
      // bounds exception in return r.substring(end+1, len). This can happen if
105
      // precision is 1 and the logger name ends with a dot.
106
213
      LogString::size_type end = buf.length() - 1;
107
108
1.50k
      for (LogString::size_type i = count; i > 0; i--)
109
1.40k
      {
110
1.40k
        end = buf.rfind(0x2E /* '.' */, end - 1);
111
112
1.40k
        if ((end == LogString::npos) || (end < nameStart))
113
122
        {
114
122
          return;
115
122
        }
116
1.40k
      }
117
118
91
      buf.erase(buf.begin() + nameStart, buf.begin() + (end + 1));
119
91
    }
120
};
121
122
/**
123
 * Fragment of an pattern abbreviator.
124
 *
125
 */
126
class PatternAbbreviatorFragment
127
{
128
    /**
129
     * Count of initial characters of element to output.
130
     */
131
    LogString::size_type charCount;
132
133
    /**
134
     *  Character used to represent dropped characters.
135
     * '\0' indicates no representation of dropped characters.
136
     */
137
    logchar ellipsis;
138
139
  public:
140
    /**
141
     * Creates a PatternAbbreviatorFragment.
142
     * @param charCount number of initial characters to preserve.
143
     * @param ellipsis character to represent elimination of characters,
144
     *    '\0' if no ellipsis is desired.
145
     */
146
    PatternAbbreviatorFragment(
147
      const int charCount1, const logchar ellipsis1)
148
163k
      : charCount(charCount1), ellipsis(ellipsis1)
149
163k
    {
150
163k
    }
log4cxx::pattern::PatternAbbreviatorFragment::PatternAbbreviatorFragment(int, char)
Line
Count
Source
148
91.0k
      : charCount(charCount1), ellipsis(ellipsis1)
149
91.0k
    {
150
91.0k
    }
log4cxx::pattern::PatternAbbreviatorFragment::PatternAbbreviatorFragment(int, wchar_t)
Line
Count
Source
148
72.6k
      : charCount(charCount1), ellipsis(ellipsis1)
149
72.6k
    {
150
72.6k
    }
151
    PatternAbbreviatorFragment() : charCount(0), ellipsis(0)
152
0
    {
153
0
    }
154
155
    PatternAbbreviatorFragment(const PatternAbbreviatorFragment& src)
156
535k
      : charCount(src.charCount), ellipsis(src.ellipsis)
157
535k
    {
158
535k
    }
159
160
    PatternAbbreviatorFragment& operator=(const PatternAbbreviatorFragment& src)
161
0
    {
162
0
      charCount = src.charCount;
163
0
      ellipsis = src.ellipsis;
164
0
      return *this;
165
0
    }
166
167
    /**
168
     * Abbreviate element of name.
169
     * @param buf buffer to receive element.
170
     * @param startPos starting index of name element.
171
     * @return starting index of next element.
172
     */
173
    LogString::size_type abbreviate(LogString& buf, LogString::size_type startPos) const
174
67.8k
    {
175
67.8k
      LogString::size_type nextDot = buf.find(0x2E /* '.' */, startPos);
176
177
67.8k
      if (nextDot != LogString::npos)
178
67.7k
      {
179
67.7k
        if ((nextDot - startPos) > charCount)
180
37.8k
        {
181
37.8k
          buf.erase(buf.begin() + (startPos + charCount), buf.begin() + nextDot);
182
37.8k
          nextDot = startPos + charCount;
183
184
37.8k
          if (ellipsis != 0x00)
185
37.2k
          {
186
37.2k
            buf.insert(nextDot, 1, ellipsis);
187
37.2k
            nextDot++;
188
37.2k
          }
189
37.8k
        }
190
191
67.7k
        nextDot++;
192
67.7k
      }
193
194
67.8k
      return nextDot;
195
67.8k
    }
log4cxx::pattern::PatternAbbreviatorFragment::abbreviate(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, unsigned long) const
Line
Count
Source
174
41.1k
    {
175
41.1k
      LogString::size_type nextDot = buf.find(0x2E /* '.' */, startPos);
176
177
41.1k
      if (nextDot != LogString::npos)
178
41.0k
      {
179
41.0k
        if ((nextDot - startPos) > charCount)
180
32.7k
        {
181
32.7k
          buf.erase(buf.begin() + (startPos + charCount), buf.begin() + nextDot);
182
32.7k
          nextDot = startPos + charCount;
183
184
32.7k
          if (ellipsis != 0x00)
185
32.5k
          {
186
32.5k
            buf.insert(nextDot, 1, ellipsis);
187
32.5k
            nextDot++;
188
32.5k
          }
189
32.7k
        }
190
191
41.0k
        nextDot++;
192
41.0k
      }
193
194
41.1k
      return nextDot;
195
41.1k
    }
log4cxx::pattern::PatternAbbreviatorFragment::abbreviate(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&, unsigned long) const
Line
Count
Source
174
26.7k
    {
175
26.7k
      LogString::size_type nextDot = buf.find(0x2E /* '.' */, startPos);
176
177
26.7k
      if (nextDot != LogString::npos)
178
26.6k
      {
179
26.6k
        if ((nextDot - startPos) > charCount)
180
5.12k
        {
181
5.12k
          buf.erase(buf.begin() + (startPos + charCount), buf.begin() + nextDot);
182
5.12k
          nextDot = startPos + charCount;
183
184
5.12k
          if (ellipsis != 0x00)
185
4.68k
          {
186
4.68k
            buf.insert(nextDot, 1, ellipsis);
187
4.68k
            nextDot++;
188
4.68k
          }
189
5.12k
        }
190
191
26.6k
        nextDot++;
192
26.6k
      }
193
194
26.7k
      return nextDot;
195
26.7k
    }
196
};
197
198
/**
199
 * Pattern abbreviator.
200
 *
201
 *
202
 */
203
class PatternAbbreviator : public NameAbbreviator
204
{
205
    /**
206
     * Element abbreviation patterns.
207
     */
208
    std::vector<PatternAbbreviatorFragment> fragments;
209
210
  public:
211
    DECLARE_ABSTRACT_LOG4CXX_OBJECT(PatternAbbreviator)
212
0
    BEGIN_LOG4CXX_CAST_MAP()
213
0
    LOG4CXX_CAST_ENTRY(PatternAbbreviator)
214
0
    LOG4CXX_CAST_ENTRY_CHAIN(NameAbbreviator)
215
0
    END_LOG4CXX_CAST_MAP()
216
    /**
217
     * Create PatternAbbreviator.
218
     *
219
     * @param fragments element abbreviation patterns.
220
     */
221
    PatternAbbreviator(const std::vector<PatternAbbreviatorFragment>& fragments1) :
222
4.33k
      fragments(fragments1)
223
4.33k
    {
224
4.33k
      if (fragments1.size() == 0)
225
0
      {
226
0
        throw IllegalArgumentException(LOG4CXX_STR("fragments parameter must contain at least one element"));
227
0
      }
228
4.33k
    }
229
230
    /**
231
     * Abbreviate name.
232
     * @param buf buffer that abbreviated name is appended.
233
     * @param nameStart start of name.
234
     */
235
    void abbreviate(LogString::size_type nameStart, LogString& buf) const override
236
752
    {
237
      //
238
      //  all non-terminal patterns are executed once
239
      //
240
752
      LogString::size_type pos = nameStart;
241
242
4.35k
      for (LogString::size_type i = 0; (i < (fragments.size() - 1)) && (pos < buf.length());
243
3.59k
        i++)
244
3.59k
      {
245
3.59k
        pos = fragments[i].abbreviate(buf, pos);
246
3.59k
      }
247
248
      //
249
      //   last pattern in executed repeatedly
250
      //
251
752
      PatternAbbreviatorFragment terminalFragment =
252
752
        fragments[fragments.size() - 1];
253
254
64.9k
      while (pos < buf.length())
255
64.2k
      {
256
64.2k
        pos = terminalFragment.abbreviate(buf, pos);
257
64.2k
      }
258
752
    }
log4cxx::pattern::PatternAbbreviator::abbreviate(unsigned long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) const
Line
Count
Source
236
372
    {
237
      //
238
      //  all non-terminal patterns are executed once
239
      //
240
372
      LogString::size_type pos = nameStart;
241
242
2.02k
      for (LogString::size_type i = 0; (i < (fragments.size() - 1)) && (pos < buf.length());
243
1.64k
        i++)
244
1.64k
      {
245
1.64k
        pos = fragments[i].abbreviate(buf, pos);
246
1.64k
      }
247
248
      //
249
      //   last pattern in executed repeatedly
250
      //
251
372
      PatternAbbreviatorFragment terminalFragment =
252
372
        fragments[fragments.size() - 1];
253
254
39.8k
      while (pos < buf.length())
255
39.4k
      {
256
39.4k
        pos = terminalFragment.abbreviate(buf, pos);
257
39.4k
      }
258
372
    }
log4cxx::pattern::PatternAbbreviator::abbreviate(unsigned long, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&) const
Line
Count
Source
236
380
    {
237
      //
238
      //  all non-terminal patterns are executed once
239
      //
240
380
      LogString::size_type pos = nameStart;
241
242
2.33k
      for (LogString::size_type i = 0; (i < (fragments.size() - 1)) && (pos < buf.length());
243
1.95k
        i++)
244
1.95k
      {
245
1.95k
        pos = fragments[i].abbreviate(buf, pos);
246
1.95k
      }
247
248
      //
249
      //   last pattern in executed repeatedly
250
      //
251
380
      PatternAbbreviatorFragment terminalFragment =
252
380
        fragments[fragments.size() - 1];
253
254
25.1k
      while (pos < buf.length())
255
24.7k
      {
256
24.7k
        pos = terminalFragment.abbreviate(buf, pos);
257
24.7k
      }
258
380
    }
259
};
260
}
261
}
262
263
IMPLEMENT_LOG4CXX_OBJECT(NOPAbbreviator)
264
IMPLEMENT_LOG4CXX_OBJECT(MaxElementAbbreviator)
265
IMPLEMENT_LOG4CXX_OBJECT(PatternAbbreviator)
266
267
268
269
NameAbbreviatorPtr NameAbbreviator::getAbbreviator(const LogString& pattern)
270
23.9k
{
271
23.9k
  if (pattern.length() > 0)
272
8.47k
  {
273
    //  if pattern is just spaces and numbers then
274
    //     use MaxElementAbbreviator
275
8.47k
    LogString trimmed(StringHelper::trim(pattern));
276
277
8.47k
    if (trimmed.length() == 0)
278
529
    {
279
529
      return getDefaultAbbreviator();
280
529
    }
281
282
7.94k
    LogString::size_type i = 0;
283
284
7.94k
    while (
285
82.9k
      (i < trimmed.length()) && (trimmed[i] >= 0x30 /* '0' */)
286
76.5k
      && (trimmed[i] <= 0x39 /* '9' */))
287
75.0k
    {
288
75.0k
      i++;
289
75.0k
    }
290
291
    //
292
    //  if all blanks and digits
293
    //
294
7.94k
    if (i == trimmed.length())
295
3.61k
    {
296
3.61k
      int len = 256;
297
3.61k
      try
298
3.61k
      {
299
3.61k
        len = StringHelper::toInt(trimmed);
300
3.61k
      }
301
3.61k
      catch (const std::out_of_range& ex)
302
3.61k
      {
303
534
        LogLog::warn(LOG4CXX_STR("Invalid name abreviator pattern: ") + pattern, ex);
304
534
      }
305
306
3.61k
      if(len > 256){
307
660
        len = 256;
308
2.95k
      }else if( len < 0 ){
309
0
        len = 0;
310
0
      }
311
312
3.61k
      return std::make_shared<MaxElementAbbreviator>(len);
313
3.61k
    }
314
315
4.33k
    std::vector<PatternAbbreviatorFragment> fragments;
316
4.33k
    logchar ellipsis;
317
4.33k
    int charCount;
318
4.33k
    LogString::size_type pos = 0;
319
320
164k
    while (pos < trimmed.length())
321
163k
    {
322
163k
      LogString::size_type ellipsisPos = pos;
323
324
163k
      if (trimmed[pos] == 0x2A /* '*' */)
325
3.17k
      {
326
3.17k
        charCount = INT_MAX;
327
3.17k
        ellipsisPos++;
328
3.17k
      }
329
160k
      else
330
160k
      {
331
160k
        if ((trimmed[pos] >= 0x30 /* '0' */)
332
6.47k
          && (trimmed[pos] <= 0x39 /* '9' */))
333
2.51k
        {
334
2.51k
          charCount = trimmed[pos] - 0x30 /* '0' */;
335
2.51k
          ellipsisPos++;
336
2.51k
        }
337
158k
        else
338
158k
        {
339
158k
          charCount = 0;
340
158k
        }
341
160k
      }
342
343
163k
      ellipsis = 0;
344
345
163k
      if (ellipsisPos < trimmed.length())
346
162k
      {
347
162k
        ellipsis = trimmed[ellipsisPos];
348
349
162k
        if (ellipsis == 0x2E /* '.' */)
350
155k
        {
351
155k
          ellipsis = 0;
352
155k
        }
353
162k
      }
354
355
163k
      fragments.push_back(PatternAbbreviatorFragment(charCount, ellipsis));
356
163k
      pos = trimmed.find(0x2E /* '.' */, pos);
357
358
163k
      if (pos == LogString::npos)
359
3.48k
      {
360
3.48k
        break;
361
3.48k
      }
362
363
160k
      pos++;
364
160k
    }
365
366
4.33k
    return std::make_shared<PatternAbbreviator>(fragments);
367
7.94k
  }
368
369
  //
370
  //  no matching abbreviation, return defaultAbbreviator
371
  //
372
15.4k
  return getDefaultAbbreviator();
373
23.9k
}
log4cxx::pattern::NameAbbreviator::getAbbreviator(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Line
Count
Source
270
14.2k
{
271
14.2k
  if (pattern.length() > 0)
272
4.69k
  {
273
    //  if pattern is just spaces and numbers then
274
    //     use MaxElementAbbreviator
275
4.69k
    LogString trimmed(StringHelper::trim(pattern));
276
277
4.69k
    if (trimmed.length() == 0)
278
312
    {
279
312
      return getDefaultAbbreviator();
280
312
    }
281
282
4.38k
    LogString::size_type i = 0;
283
284
4.38k
    while (
285
44.3k
      (i < trimmed.length()) && (trimmed[i] >= 0x30 /* '0' */)
286
40.9k
      && (trimmed[i] <= 0x39 /* '9' */))
287
39.9k
    {
288
39.9k
      i++;
289
39.9k
    }
290
291
    //
292
    //  if all blanks and digits
293
    //
294
4.38k
    if (i == trimmed.length())
295
1.78k
    {
296
1.78k
      int len = 256;
297
1.78k
      try
298
1.78k
      {
299
1.78k
        len = StringHelper::toInt(trimmed);
300
1.78k
      }
301
1.78k
      catch (const std::out_of_range& ex)
302
1.78k
      {
303
285
        LogLog::warn(LOG4CXX_STR("Invalid name abreviator pattern: ") + pattern, ex);
304
285
      }
305
306
1.78k
      if(len > 256){
307
278
        len = 256;
308
1.50k
      }else if( len < 0 ){
309
0
        len = 0;
310
0
      }
311
312
1.78k
      return std::make_shared<MaxElementAbbreviator>(len);
313
1.78k
    }
314
315
2.59k
    std::vector<PatternAbbreviatorFragment> fragments;
316
2.59k
    logchar ellipsis;
317
2.59k
    int charCount;
318
2.59k
    LogString::size_type pos = 0;
319
320
91.5k
    while (pos < trimmed.length())
321
91.0k
    {
322
91.0k
      LogString::size_type ellipsisPos = pos;
323
324
91.0k
      if (trimmed[pos] == 0x2A /* '*' */)
325
942
      {
326
942
        charCount = INT_MAX;
327
942
        ellipsisPos++;
328
942
      }
329
90.1k
      else
330
90.1k
      {
331
90.1k
        if ((trimmed[pos] >= 0x30 /* '0' */)
332
4.43k
          && (trimmed[pos] <= 0x39 /* '9' */))
333
1.61k
        {
334
1.61k
          charCount = trimmed[pos] - 0x30 /* '0' */;
335
1.61k
          ellipsisPos++;
336
1.61k
        }
337
88.5k
        else
338
88.5k
        {
339
88.5k
          charCount = 0;
340
88.5k
        }
341
90.1k
      }
342
343
91.0k
      ellipsis = 0;
344
345
91.0k
      if (ellipsisPos < trimmed.length())
346
90.7k
      {
347
90.7k
        ellipsis = trimmed[ellipsisPos];
348
349
90.7k
        if (ellipsis == 0x2E /* '.' */)
350
85.9k
        {
351
85.9k
          ellipsis = 0;
352
85.9k
        }
353
90.7k
      }
354
355
91.0k
      fragments.push_back(PatternAbbreviatorFragment(charCount, ellipsis));
356
91.0k
      pos = trimmed.find(0x2E /* '.' */, pos);
357
358
91.0k
      if (pos == LogString::npos)
359
2.16k
      {
360
2.16k
        break;
361
2.16k
      }
362
363
88.9k
      pos++;
364
88.9k
    }
365
366
2.59k
    return std::make_shared<PatternAbbreviator>(fragments);
367
4.38k
  }
368
369
  //
370
  //  no matching abbreviation, return defaultAbbreviator
371
  //
372
9.55k
  return getDefaultAbbreviator();
373
14.2k
}
log4cxx::pattern::NameAbbreviator::getAbbreviator(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&)
Line
Count
Source
270
9.66k
{
271
9.66k
  if (pattern.length() > 0)
272
3.78k
  {
273
    //  if pattern is just spaces and numbers then
274
    //     use MaxElementAbbreviator
275
3.78k
    LogString trimmed(StringHelper::trim(pattern));
276
277
3.78k
    if (trimmed.length() == 0)
278
217
    {
279
217
      return getDefaultAbbreviator();
280
217
    }
281
282
3.56k
    LogString::size_type i = 0;
283
284
3.56k
    while (
285
38.5k
      (i < trimmed.length()) && (trimmed[i] >= 0x30 /* '0' */)
286
35.6k
      && (trimmed[i] <= 0x39 /* '9' */))
287
35.0k
    {
288
35.0k
      i++;
289
35.0k
    }
290
291
    //
292
    //  if all blanks and digits
293
    //
294
3.56k
    if (i == trimmed.length())
295
1.82k
    {
296
1.82k
      int len = 256;
297
1.82k
      try
298
1.82k
      {
299
1.82k
        len = StringHelper::toInt(trimmed);
300
1.82k
      }
301
1.82k
      catch (const std::out_of_range& ex)
302
1.82k
      {
303
249
        LogLog::warn(LOG4CXX_STR("Invalid name abreviator pattern: ") + pattern, ex);
304
249
      }
305
306
1.82k
      if(len > 256){
307
382
        len = 256;
308
1.44k
      }else if( len < 0 ){
309
0
        len = 0;
310
0
      }
311
312
1.82k
      return std::make_shared<MaxElementAbbreviator>(len);
313
1.82k
    }
314
315
1.74k
    std::vector<PatternAbbreviatorFragment> fragments;
316
1.74k
    logchar ellipsis;
317
1.74k
    int charCount;
318
1.74k
    LogString::size_type pos = 0;
319
320
73.1k
    while (pos < trimmed.length())
321
72.6k
    {
322
72.6k
      LogString::size_type ellipsisPos = pos;
323
324
72.6k
      if (trimmed[pos] == 0x2A /* '*' */)
325
2.23k
      {
326
2.23k
        charCount = INT_MAX;
327
2.23k
        ellipsisPos++;
328
2.23k
      }
329
70.4k
      else
330
70.4k
      {
331
70.4k
        if ((trimmed[pos] >= 0x30 /* '0' */)
332
2.04k
          && (trimmed[pos] <= 0x39 /* '9' */))
333
900
        {
334
900
          charCount = trimmed[pos] - 0x30 /* '0' */;
335
900
          ellipsisPos++;
336
900
        }
337
69.5k
        else
338
69.5k
        {
339
69.5k
          charCount = 0;
340
69.5k
        }
341
70.4k
      }
342
343
72.6k
      ellipsis = 0;
344
345
72.6k
      if (ellipsisPos < trimmed.length())
346
72.1k
      {
347
72.1k
        ellipsis = trimmed[ellipsisPos];
348
349
72.1k
        if (ellipsis == 0x2E /* '.' */)
350
69.1k
        {
351
69.1k
          ellipsis = 0;
352
69.1k
        }
353
72.1k
      }
354
355
72.6k
      fragments.push_back(PatternAbbreviatorFragment(charCount, ellipsis));
356
72.6k
      pos = trimmed.find(0x2E /* '.' */, pos);
357
358
72.6k
      if (pos == LogString::npos)
359
1.32k
      {
360
1.32k
        break;
361
1.32k
      }
362
363
71.3k
      pos++;
364
71.3k
    }
365
366
1.74k
    return std::make_shared<PatternAbbreviator>(fragments);
367
3.56k
  }
368
369
  //
370
  //  no matching abbreviation, return defaultAbbreviator
371
  //
372
5.87k
  return getDefaultAbbreviator();
373
9.66k
}
374
375
/**
376
 * Gets default abbreviator.
377
 *
378
 * @return default abbreviator.
379
 */
380
NameAbbreviatorPtr NameAbbreviator::getDefaultAbbreviator()
381
15.9k
{
382
15.9k
  static WideLife<NameAbbreviatorPtr> def = std::make_shared<NOPAbbreviator>();
383
15.9k
  return def;
384
15.9k
}
385