MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / get_text

Function get_text

sql/sql_lex.cc:627–751  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

625*/
626
627static char *get_text(Lex_input_stream *lip, int pre_skip, int post_skip)
628{
629 reg1 uchar c,sep;
630 uint found_escape=0;
631 const CHARSET_INFO *cs= lip->m_thd->charset();
632
633 lip->tok_bitmap= 0;
634 sep= lip->yyGetLast(); // String should end with this
635 while (! lip->eof())
636 {
637 c= lip->yyGet();
638 lip->tok_bitmap|= c;
639#ifdef USE_MB
640 {
641 int l;
642 if (use_mb(cs) &&
643 (l = my_ismbchar(cs,
644 lip->get_ptr() -1,
645 lip->get_end_of_query()))) {
646 lip->skip_binary(l-1);
647 continue;
648 }
649 }
650#endif
651 if (c == '\\' &&
652 !(lip->m_thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES))
653 { // Escaped character
654 found_escape=1;
655 if (lip->eof())
656 return 0;
657 lip->yySkip();
658 }
659 else if (c == sep)
660 {
661 if (c == lip->yyGet()) // Check if two separators in a row
662 {
663 found_escape=1; // duplicate. Remember for delete
664 continue;
665 }
666 else
667 lip->yyUnget();
668
669 /* Found end. Unescape and return string */
670 const char *str, *end;
671 char *start;
672
673 str= lip->get_tok_start();
674 end= lip->get_ptr();
675 /* Extract the text from the token */
676 str += pre_skip;
677 end -= post_skip;
678 DBUG_ASSERT(end >= str);
679
680 if (!(start= (char*) lip->m_thd->alloc((uint) (end-str)+1)))
681 return (char*) ""; // Sql_alloc has set error flag
682
683 lip->m_cpp_text_start= lip->get_cpp_tok_start() + pre_skip;
684 lip->m_cpp_text_end= lip->get_cpp_ptr() - post_skip;

Callers 1

lex_one_tokenFunction · 0.85

Calls 13

yyGetLastMethod · 0.80
yyGetMethod · 0.80
get_ptrMethod · 0.80
get_end_of_queryMethod · 0.80
skip_binaryMethod · 0.80
yySkipMethod · 0.80
yyUngetMethod · 0.80
get_tok_startMethod · 0.80
get_cpp_tok_startMethod · 0.80
get_cpp_ptrMethod · 0.80
charsetMethod · 0.45
eofMethod · 0.45

Tested by

no test coverage detected