[vlc-devel] commit: stream_ReadLine: handle MacOS-style end-of-line (fixes #2156) ( Rémi Denis-Courmont )

git version control git at videolan.org
Wed Feb 17 21:39:18 CET 2010


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Feb 17 22:37:36 2010 +0200| [5af0a5d418c0be1c83e5df434ab9d34ae27d41c0] | committer: Rémi Denis-Courmont 

stream_ReadLine: handle MacOS-style end-of-line (fixes #2156)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5af0a5d418c0be1c83e5df434ab9d34ae27d41c0
---

 src/input/stream.c |   43 ++++++++++++++++++++++++-------------------
 1 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/src/input/stream.c b/src/input/stream.c
index d068986..00cd28e 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -1567,33 +1567,38 @@ char *stream_ReadLine( stream_t *s )
         {
             /* UTF-8: 0A <LF> */
             psz_eol = memchr( p_data, '\n', i_data );
+            if( psz_eol == NULL )
+                /* UTF-8: 0D <CR> */
+                psz_eol = memchr( p_data, '\r', i_data );
         }
         else
         {
-            const uint8_t *p = p_data;
-            const uint8_t *p_last = p + i_data - s->p_text->i_char_width;
+            const uint8_t *p_last = p_data + i_data - s->p_text->i_char_width;
+            uint16_t eol = s->p_text->b_little_endian ? 0x0A00 : 0x00A0;
 
             assert( s->p_text->i_char_width == 2 );
-            if( s->p_text->b_little_endian == true)
+            psz_eol = NULL;
+            /* UTF-16: 000A <LF> */
+            for( const uint8_t *p = p_data; p <= p_last; p += 2 )
             {
-                /* UTF-16LE: 0A 00 <LF> */
-                while( p <= p_last && ( p[0] != 0x0A || p[1] != 0x00 ) )
-                    p += 2;
-            }
-            else
-            {
-                /* UTF-16BE: 00 0A <LF> */
-                while( p <= p_last && ( p[1] != 0x0A || p[0] != 0x00 ) )
-                    p += 2;
+                if( U16_AT( p ) == eol )
+                {
+                     psz_eol = (char *)p + 1;
+                     break;
+                }
             }
 
-            if( p > p_last )
-            {
-                psz_eol = NULL;
-            }
-            else
-            {
-                psz_eol = (char *)p + 1;
+            if( psz_eol == NULL )
+            {   /* UTF-16: 000D <CR> */
+                eol = s->p_text->b_little_endian ? 0x0D00 : 0x00D0;
+                for( const uint8_t *p = p_data; p <= p_last; p += 2 )
+                {
+                    if( U16_AT( p ) == eol )
+                    {
+                        psz_eol = (char *)p + 1;
+                        break;
+                    }
+                }
             }
         }
 




More information about the vlc-devel mailing list