OSDN Git Service

* Tested: LibEditText_BackFindString() API
authorKoine Yuusuke(koinec) <koinec@users.sourceforge.jp>
Mon, 10 Aug 2015 03:22:41 +0000 (12:22 +0900)
committerKoine Yuusuke(koinec) <koinec@users.sourceforge.jp>
Mon, 10 Aug 2015 03:22:41 +0000 (12:22 +0900)
libedittext/drd64_libedittext_cursorfind.c
libedittext/test_libedittext_cursorfind.c

index 95b7da3..11d8815 100644 (file)
@@ -348,15 +348,14 @@ int
        int             i_round;
        Byte    *pb_start;
        DWord   dw_end;
-       DWord   dw_pos;
+       DWord   dw_pos[2];
        DWord   dw_lnow;
-       DWord   dw_len;
+       DWord   dw_len[2];
        DWord   dw_lidbase;
        DWord   dw_nowbase;
-       DWord   dw_oldbase;
+       DWord   dw_cnt;
        LibEditText_LineInfo    *p_line;
        regmatch_t      t_match;
-       regmatch_t      t_oldmatch;
 
        assert( NULL != p_tinfo );
        assert( NULL != p_cursor );
@@ -370,6 +369,7 @@ int
        pb_start        = p_tinfo->pb_text + p_line->dw_start;
        dw_end          = *pdw_pos;
        i_round         = 0x00;
+       dw_cnt          = 0;
 
        if( 0 == dw_end )       {
                if( 1 == p_tinfo->dw_maxline )
@@ -392,18 +392,19 @@ int
        do      {
                
                dw_nowbase      = 0;
-               dw_oldbase      = 0;
                do      {
+                       dw_pos[1]       = dw_pos[0];
+                       dw_len[1]       = dw_len[0];
+
                        i_result        = regexec( &(p_cursor->t_findreg),
                                                                (const char *)pb_start, 1, &t_match, 0x00 );
-
                        if( 0x00 == i_result )  {
-                               t_oldmatch.rm_so        = t_match.rm_so;
-                               t_oldmatch.rm_eo        = t_match.rm_eo;
-                               dw_oldbase                      = dw_nowbase;
-                       
+                               dw_pos[0]       = dw_nowbase + t_match.rm_so;
+                               dw_len[0]       = t_match.rm_eo - t_match.rm_so;
+
                                pb_start        += t_match.rm_eo;
                                dw_nowbase      += t_match.rm_eo;
+                               dw_cnt++;
                        }
                }while(( 0x00 == i_result ) && ( dw_nowbase < dw_end ));
 
@@ -418,11 +419,19 @@ int
 
                assert( REG_NOMATCH == i_result );
                if( 0 < dw_nowbase )    {
-                       dw_pos  = dw_oldbase + t_oldmatch.rm_so;
-                       dw_len  = t_oldmatch.rm_eo - t_oldmatch.rm_so;
-                       // Find String Line is dw_lnow.
-                       i_result        = 0x00;
-                       break;
+                       if( 1 < dw_cnt )        {
+                               dw_pos[0]       = dw_pos[1];
+                               dw_len[0]       = dw_len[1];
+                               i_result        = 0x00;
+                               break;
+                       }
+                       else    {
+                               if( dw_pos[0] < dw_end )        {
+                                       i_result        = 0x00;
+                                       break;
+                               }
+                       }
+
                }
 
                // Going to Before-Line ---
@@ -445,10 +454,10 @@ int
                { return LIBEDITTEXT_RET_FINDNOMATCH; } // NO match string in Text. 
 
        assert( dw_lnow < p_tinfo->dw_maxline );
-       assert( dw_pos < p_line->dw_strlen );
+       assert( dw_pos[0] < p_line->dw_strlen );
 
-       *pdw_pos                = dw_pos;
-       *pdw_len                = dw_len;
+       *pdw_pos                = dw_pos[0];
+       *pdw_len                = dw_len[0];
        *pdw_findlid    = p_line->dw_id;
        *pdw_line               = dw_lnow;
        
@@ -504,7 +513,7 @@ int
        }
 
        // Exec Find ---
-       dw_pstart       = p_cursor->dw_pos;
+       dw_pstart       = (( 0 < p_cursor->dw_pos ) ? (p_cursor->dw_pos - 1) : 0 );
        i_retfind       = LibEditText_CursorFind_ExecBackFindString(
                                                        p_tinfo, p_cursor, &dw_findlid, &dw_line, &dw_pstart, &dw_len );
        if( 0x00 > i_retfind )  {
index 2175254..ba05a9a 100644 (file)
@@ -177,6 +177,97 @@ void Test_LibEditText_API_CursorAPI_FindNextString_test00_001(void)
 }
 
 
+/* LibEditText_BackFindString *****************************************/
+/*--------------------------------------------------------------------*/
+void Test_LibEditText_API_CursorAPI_BackFindString_test00_001(void)
+{
+       int             i_result;
+       int             i_retfind;
+       int             i_tinfoid;
+       int             i_curid;
+       char    *pstr_value;
+       DWord   dw_line;
+       DWord   dw_pos;
+       DWord   dw_len;
+
+       i_result        = LibEditText_Init();
+       CU_ASSERT( 0x00 == i_result );
+       
+       i_tinfoid       = LibEditText_OpenTextFile("./testdata", "drcc_testfile.c");
+       CU_ASSERT( 0x00 <= i_tinfoid );
+
+       i_curid         = LibEditText_AllocCursor( i_tinfoid, 13 );
+       CU_ASSERT( 0x00 <= i_curid );
+
+       i_result        = LibEditText_Debug_DebugTextInfo(
+                                               i_tinfoid, 0x01, "API BackFindString test00_001" );
+       CU_ASSERT( 0x00 == i_result );
+
+       puts("[A] Find Result ---2----+----3----+----4----+----5----+----6----+----7----+----8");
+
+       // Find 01 ---
+       i_retfind       = LibEditText_BackFindString( i_tinfoid, i_curid, "CT", 2, &dw_len );
+       CU_ASSERT( LIBEDITTEXT_RET_FINDMATCH_ROUND == i_retfind );
+       i_result        = LibEditText_GetCursorPosition( i_tinfoid, i_curid, &dw_line, &dw_pos );
+       CU_ASSERT( 0x00 == i_result );
+       pstr_value      = LibEditText_GetCursorLineString( i_tinfoid, i_curid, NULL );
+       printf("  Find 01: [%u:%u(%u)] %s", dw_line, dw_pos, dw_len, pstr_value );
+
+       // Find 02 ---
+       i_retfind       = LibEditText_BackFindString( i_tinfoid, i_curid, "CT", 2, &dw_len );
+       CU_ASSERT( LIBEDITTEXT_RET_FINDMATCH == i_retfind );
+       i_result        = LibEditText_GetCursorPosition( i_tinfoid, i_curid, &dw_line, &dw_pos );
+       CU_ASSERT( 0x00 == i_result );
+       pstr_value      = LibEditText_GetCursorLineString( i_tinfoid, i_curid, NULL );
+       printf("  Find 02: [%u:%u(%u)] %s", dw_line, dw_pos, dw_len, pstr_value );
+
+       // Find 03 ---
+       i_retfind       = LibEditText_BackFindString( i_tinfoid, i_curid, "CT", 2, &dw_len );
+       CU_ASSERT( LIBEDITTEXT_RET_FINDMATCH == i_retfind );
+       i_result        = LibEditText_GetCursorPosition( i_tinfoid, i_curid, &dw_line, &dw_pos );
+       CU_ASSERT( 0x00 == i_result );
+       pstr_value      = LibEditText_GetCursorLineString( i_tinfoid, i_curid, NULL );
+       printf("  Find 03: [%u:%u(%u)] %s", dw_line, dw_pos, dw_len, pstr_value );
+
+       // Find 04 ---
+       i_retfind       = LibEditText_BackFindString( i_tinfoid, i_curid, "CT", 2, &dw_len );
+       CU_ASSERT( LIBEDITTEXT_RET_FINDMATCH == i_retfind );
+       i_result        = LibEditText_GetCursorPosition( i_tinfoid, i_curid, &dw_line, &dw_pos );
+       CU_ASSERT( 0x00 == i_result );
+       pstr_value      = LibEditText_GetCursorLineString( i_tinfoid, i_curid, NULL );
+       printf("  Find 04: [%u:%u(%u)] %s", dw_line, dw_pos, dw_len, pstr_value );
+
+       // Find 05 ---
+       i_retfind       = LibEditText_BackFindString( i_tinfoid, i_curid, "CT", 2, &dw_len );
+       CU_ASSERT( LIBEDITTEXT_RET_FINDMATCH_ROUND == i_retfind );
+       i_result        = LibEditText_GetCursorPosition( i_tinfoid, i_curid, &dw_line, &dw_pos );
+       CU_ASSERT( 0x00 == i_result );
+       pstr_value      = LibEditText_GetCursorLineString( i_tinfoid, i_curid, NULL );
+       printf("  Find 05: [%u:%u(%u)] %s", dw_line, dw_pos, dw_len, pstr_value );
+/*     
+       while( LIBEDITTEXT_RET_FINDMATCH == i_retfind ) {
+               i_result        = LibEditText_GetCursorPosition( i_tinfoid, i_curid, &dw_line, &dw_pos );
+               CU_ASSERT( 0x00 == i_result );
+               pstr_value      = LibEditText_GetCursorLineString( i_tinfoid, i_curid, NULL );
+               printf("  FindNext: [%u:%u(%u)] %s", dw_line, dw_pos, dw_len, pstr_value );
+
+               i_retfind       = LibEditText_FindNextString( i_tinfoid, i_curid, &dw_len );
+               CU_ASSERT( 0x00 <= i_retfind );
+       }
+*/
+       i_result        = LibEditText_FreeCursor( i_tinfoid, i_curid );
+       CU_ASSERT( 0x00 == i_result );
+
+       i_result        = LibEditText_CloseFile( i_tinfoid );
+       CU_ASSERT( 0x00 == i_result );
+
+       i_result        = LibEditText_Term();
+       CU_ASSERT( 0x00 == i_result );
+       
+       return;
+}
+
+
 /*----------------------------------------------------------------------
 ----------------------------------------------------------------------*/
 DRD64_TEST_LIBEDITTEXT_CURSORFIND_EXTERN
@@ -193,6 +284,9 @@ int
        CU_add_test( pt_edittext, "EditText_CursorAPI_FindNextString_test00_001",
                                                                 Test_LibEditText_API_CursorAPI_FindNextString_test00_001 );
 
+       CU_add_test( pt_edittext, "EditText_CursorAPI_BackFindString_test00_001",
+                                                                Test_LibEditText_API_CursorAPI_BackFindString_test00_001 );
+
        return 0x00;
 }