LCOV - code coverage report
Current view: top level - frmts/pcidsk/sdk/segment - cpcidsk_tex.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 0 38 0.0 %
Date: 2024-11-25 23:50:41 Functions: 0 7 0.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Purpose:  Implementation of the CPCIDSK_TEX class.
       4             :  *
       5             :  ******************************************************************************
       6             :  * Copyright (c) 2010
       7             :  * PCI Geomatics, 90 Allstate Parkway, Markham, Ontario, Canada.
       8             :  *
       9             :  * SPDX-License-Identifier: MIT
      10             :  ****************************************************************************/
      11             : 
      12             : #include "pcidsk_exception.h"
      13             : #include "segment/cpcidsk_tex.h"
      14             : #include <cassert>
      15             : #include <cstring>
      16             : 
      17             : using namespace PCIDSK;
      18             : 
      19             : /************************************************************************/
      20             : /*                            CPCIDSK_TEX()                             */
      21             : /************************************************************************/
      22             : 
      23           0 : CPCIDSK_TEX::CPCIDSK_TEX( PCIDSKFile *fileIn, int segmentIn,
      24           0 :                           const char *segment_pointer )
      25           0 :         : CPCIDSKSegment( fileIn, segmentIn, segment_pointer )
      26             : 
      27             : {
      28           0 : }
      29             : 
      30             : /************************************************************************/
      31             : /*                            ~CPCIDSK_TEX()                            */
      32             : /************************************************************************/
      33             : 
      34           0 : CPCIDSK_TEX::~CPCIDSK_TEX()
      35             : 
      36             : {
      37           0 : }
      38             : 
      39             : /************************************************************************/
      40             : /*                              ReadText()                              */
      41             : /************************************************************************/
      42             : 
      43           0 : std::string CPCIDSK_TEX::ReadText()
      44             : 
      45             : {
      46           0 :     PCIDSKBuffer seg_data;
      47             : 
      48           0 :     seg_data.SetSize( (int) GetContentSize() );
      49             : 
      50           0 :     ReadFromFile( seg_data.buffer, 0, seg_data.buffer_size );
      51             : 
      52             :     int i;
      53           0 :     char *tbuffer = (char *) seg_data.buffer;
      54             : 
      55           0 :     for( i = 0; i < seg_data.buffer_size; i++ )
      56             :     {
      57           0 :         if( tbuffer[i] == '\r' )
      58           0 :             tbuffer[i] = '\n';
      59             : 
      60           0 :         if( tbuffer[i] == '\0' )
      61           0 :             break;
      62             :     }
      63             : 
      64           0 :     return std::string( (const char *) seg_data.buffer, i );
      65             : }
      66             : 
      67             : /************************************************************************/
      68             : /*                             WriteText()                              */
      69             : /************************************************************************/
      70             : 
      71           0 : void CPCIDSK_TEX::WriteText( const std::string &text_in )
      72             : 
      73             : {
      74             :     // Transform all \n's to \r's (chr(10) to char(13)).
      75           0 :     unsigned int i, i_out = 0;
      76           0 :     std::string text = text_in;
      77             : 
      78           0 :     for( i = 0; i < text.size(); i++ )
      79             :     {
      80           0 :         if( text[i] == '\0' )
      81             :         {
      82           0 :             text.resize( i );
      83           0 :             break;
      84             :         }
      85             : 
      86           0 :         if( text[i] == '\n' && text[i+1] == '\r' )
      87             :         {
      88           0 :             text[i_out++] = '\r';
      89           0 :             i++;
      90             :         }
      91           0 :         else if( text[i] == '\r' && text[i+1] == '\n' )
      92             :         {
      93           0 :             text[i_out++] = '\r';
      94           0 :             i++;
      95             :         }
      96           0 :         else if( text[i] == '\n' )
      97           0 :             text[i_out++] = '\r';
      98             :         else
      99           0 :             text[i_out++] = text[i];
     100             :     }
     101             : 
     102           0 :     text.resize( i_out );
     103             : 
     104             :     // make sure we have a newline at the end.
     105             : 
     106           0 :     if( i_out > 0 && text[i_out-1] != '\r' )
     107           0 :         text += "\r";
     108             : 
     109             :     // We really *ought* to ensure the rest of the segment
     110             :     // is zeroed out to properly adhere to the specification.
     111             :     // It might also be prudent to ensure the segment grows
     112             :     // in 32K increments to avoid "move to end of file churn"
     113             :     // if several text segments are growing a bit at a time
     114             :     // though this is uncommon.
     115             : 
     116           0 :     WriteToFile( text.c_str(), 0, text.size() + 1 );
     117           0 : }

Generated by: LCOV version 1.14