@@ -2072,11 +2072,11 @@ string_istitle(PyStringObject *self, PyObject *args)
20722072
20732073
20742074static char splitlines__doc__ [] =
2075- "S.splitlines([maxsplit ]]) -> list of strings\n\
2075+ "S.splitlines([keepends ]]) -> list of strings\n\
20762076\n\
20772077Return a list of the lines in S, breaking at line boundaries.\n\
2078- If maxsplit is given, at most maxsplit are done. Line breaks are not \n\
2079- included in the resulting list ." ;
2078+ Line breaks are not included in the resulting list unless keepends \n\
2079+ is given and true ." ;
20802080
20812081#define SPLIT_APPEND (data , left , right ) \
20822082 str = PyString_FromStringAndSize(data + left, right - left); \
@@ -2092,43 +2092,43 @@ included in the resulting list.";
20922092static PyObject *
20932093string_splitlines (PyStringObject * self , PyObject * args )
20942094{
2095- int maxcount = -1 ;
20962095 register int i ;
20972096 register int j ;
20982097 int len ;
2098+ int keepends = 0 ;
20992099 PyObject * list ;
21002100 PyObject * str ;
21012101 char * data ;
21022102
2103- if (!PyArg_ParseTuple (args , "|i:splitlines" , & maxcount ))
2103+ if (!PyArg_ParseTuple (args , "|i:splitlines" , & keepends ))
21042104 return NULL ;
21052105
21062106 data = PyString_AS_STRING (self );
21072107 len = PyString_GET_SIZE (self );
21082108
2109- if (maxcount < 0 )
2110- maxcount = INT_MAX ;
2111-
21122109 list = PyList_New (0 );
21132110 if (!list )
21142111 goto onError ;
21152112
21162113 for (i = j = 0 ; i < len ; ) {
2114+ int eol ;
2115+
21172116 /* Find a line and append it */
21182117 while (i < len && data [i ] != '\n' && data [i ] != '\r' )
21192118 i ++ ;
2120- if (maxcount -- <= 0 )
2121- break ;
2122- SPLIT_APPEND (data , j , i );
21232119
21242120 /* Skip the line break reading CRLF as one line break */
2121+ eol = i ;
21252122 if (i < len ) {
21262123 if (data [i ] == '\r' && i + 1 < len &&
21272124 data [i + 1 ] == '\n' )
21282125 i += 2 ;
21292126 else
21302127 i ++ ;
2128+ if (keepends )
2129+ eol = i ;
21312130 }
2131+ SPLIT_APPEND (data , j , eol );
21322132 j = i ;
21332133 }
21342134 if (j < len ) {
@@ -2591,7 +2591,10 @@ PyString_Format(format, args)
25912591 fmt = fmt_start ;
25922592 goto unicode ;
25932593 }
2594+ if (c == 's' )
25942595 temp = PyObject_Str (v );
2596+ else
2597+ temp = PyObject_Repr (v );
25952598 if (temp == NULL )
25962599 goto error ;
25972600 if (!PyString_Check (temp )) {
0 commit comments