File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -644,6 +644,32 @@ xy_str_find (const char *str, const char *substr)
644644 return result ;
645645}
646646
647+ /**
648+ * @brief 获取字符串下一行的内容
649+ * @note 将忽略开头的换行,截取至下一个换行前(不含换行符)
650+ */
651+ static char *
652+ xy_str_take_until_newline (const char * str )
653+ {
654+ if (!str )
655+ return xy_strdup ("" );
656+
657+ const char * cur = str ;
658+ while (* cur == '\n' )
659+ cur ++ ;
660+
661+ if ('\0' == * cur )
662+ return xy_strdup ("" );
663+
664+ const char * newline = strchr (cur , '\n' );
665+ size_t len = newline ? (size_t ) (newline - cur ) : strlen (cur );
666+
667+ char * ret = xy_malloc0 (len + 1 );
668+ strncpy (ret , cur , len );
669+ ret [len ] = '\0' ;
670+ return ret ;
671+ }
672+
647673
648674
649675/******************************************************
You can’t perform that action at this time.
0 commit comments