@techee commented on this pull request.


> +     if (source_file->lang == TM_PARSER_C || source_file->lang == 
> TM_PARSER_CPP)
+       {
+               const gchar **ext;
+               const gchar *common_src_exts[] =
+                       {".c", ".C", ".cc", ".cp", ".cpp", ".cxx", ".c++", 
".CPP", ".CXX", NULL};
+
+               for (ext = common_src_exts; *ext; ext++)
+               {
+                       if (g_str_has_suffix(source_file->short_name, *ext))
+                       {
+                               source_file->is_c_source = TRUE;
+                               break;
+                       }
+               }
+       }
+

```
source_file->is_source = TRUE;
```

Yes, we could do that - makes probably more sense as the `is_source` flag is 
valid for all languages and not specific to C/C++.

```C
        if (source_file->lang == TM_PARSER_C || source_file->lang == 
TM_PARSER_CPP)
        {
                const gchar *ext = strrchr(source_file->short_name, '.');

                if (! ext)
                        source_file->is_source = FALSE;
                else
                {
                        int i;
                        const gchar *common_src_exts[] =
                                {"c", "C", "cc", "cp", "cpp", "cxx", "c++", 
"CPP", "CXX"};

                        for (i = 0; i < G_N_ELEMENTS(common_src_exts); i++)
                        {
                                if (strcmp(ext + 1, common_src_exts[i]) == 0)
                                        break
                        }

                        source_file->is_source = (i < 
G_N_ELEMENTS(common_src_exts));
                }
        }
```
Does this code offer any benefit compared to what I wrote? I personally find my 
code a bit easier to read as you avoid the extra branch where `.` is not found 
and one also has to think a bit when looking at
```
source_file->is_source = (i < G_N_ELEMENTS(common_src_exts));
```
what exactly it means.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/pull/3490#discussion_r1188530523
You are receiving this because you are subscribed to this thread.

Message ID: <geany/geany/pull/3490/review/[email protected]>

Reply via email to