Matter SDK Coverage Report
Current view: top level - lib/dnssd/minimal_mdns/core - QNameString.h (source / functions) Coverage Total Hit
Test: SHA:3f9cd168e84cd831b7699126f5296f5c5498690f Lines: 91.7 % 12 11
Test Date: 2026-04-27 19:52:19 Functions: 88.9 % 9 8

            Line data    Source code
       1              : /*
       2              :  *
       3              :  *    Copyright (c) 2022 Project CHIP Authors
       4              :  *
       5              :  *    Licensed under the Apache License, Version 2.0 (the "License");
       6              :  *    you may not use this file except in compliance with the License.
       7              :  *    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              : #pragma once
      18              : 
      19              : #include <lib/dnssd/minimal_mdns/core/QName.h>
      20              : #include <lib/support/StringBuilder.h>
      21              : 
      22              : #include <cstring>
      23              : 
      24              : namespace mdns {
      25              : namespace Minimal {
      26              : 
      27              : // Allows for a FullQName to be represented as a user-readable logging string
      28              : class QNameString
      29              : {
      30              : public:
      31              :     QNameString(const mdns::Minimal::FullQName & name);
      32              : 
      33              :     QNameString(mdns::Minimal::SerializedQNameIterator name);
      34              : 
      35            3 :     inline const char * c_str() const { return mBuffer.c_str(); }
      36              : 
      37           10 :     inline bool Fit() const { return mBuffer.Fit(); }
      38              : 
      39              :     template <size_t N>
      40            9 :     bool EndsWith(const char (&aSuffix)[N]) const
      41              :     {
      42            9 :         return EndsWith(&aSuffix[0], N - 1);
      43              :     }
      44              : 
      45              : private:
      46            9 :     bool EndsWith(const char * aSuffix, size_t aLength) const
      47              :     {
      48            9 :         if (!Fit())
      49              :         {
      50            1 :             return false;
      51              :         }
      52              : 
      53            8 :         const char * buffer = mBuffer.c_str();
      54            8 :         size_t bufferLength = strlen(buffer);
      55            8 :         if (bufferLength < aLength)
      56              :         {
      57            0 :             return false;
      58              :         }
      59              : 
      60            8 :         return memcmp(buffer + bufferLength - aLength, aSuffix, aLength) == 0;
      61              :     }
      62              : 
      63              :     static constexpr size_t kMaxQNameLength = 128;
      64              :     chip::StringBuilder<kMaxQNameLength> mBuffer;
      65              : };
      66              : 
      67              : } // namespace Minimal
      68              : } // namespace mdns
        

Generated by: LCOV version 2.0-1