[pan2: 14/268] Add options to use full subject line for saving.



commit 641f7192c2b73efc285cae0a0f9ade4a85eda903
Author: K. Haley <haleykd users sf net>
Date:   Mon Dec 13 15:00:28 2010 -0700

    Add options to use full subject line for saving.

 pan/gui/save-ui.cc                     |    9 ++++++-
 pan/usenet-utils/text-massager-test.cc |   32 +++++++++++++++-----------
 pan/usenet-utils/text-massager.cc      |   38 +++++++++++++++++--------------
 pan/usenet-utils/text-massager.h       |    2 +-
 4 files changed, 47 insertions(+), 34 deletions(-)
---
diff --git a/pan/gui/save-ui.cc b/pan/gui/save-ui.cc
index a29ec8d..73d8479 100644
--- a/pan/gui/save-ui.cc
+++ b/pan/gui/save-ui.cc
@@ -56,12 +56,16 @@ namespace
   std::string expand_download_dir_subject (const char * dir, const char * subjectline, const std::string &sep)
   {
     std::string val (dir);
-    std::string sub (subject_to_path(subjectline, sep));
+    std::string sub (subject_to_path(subjectline, false, sep));
     std::string::size_type pos;
 
     while (((pos = val.find ("%s"))) != val.npos)
       val.replace (pos, 2, sub);
 
+    sub = subject_to_path(subjectline, true, sep);
+    while (((pos = val.find ("%S"))) != val.npos)
+      val.replace (pos, 2, sub);
+
     return val;
   }
 
@@ -72,6 +76,7 @@ namespace
     const char * str = _("%g - group as one directory (alt.binaries.pictures.trains)\n"
                          "%G - group as nested directory (/alt/binaries/pictures/trains)\n"
                          "%s - subject line excerpt\n"
+                         "%S - subject line\n"
                          " \n"
                          "\"/home/user/News/Pan/%g\" becomes\n"
                          "\"/home/user/News/Pan/alt.binaries.pictures.trains\", and\n"
@@ -123,7 +128,7 @@ SaveDialog :: response_cb (GtkDialog * dialog,
       self->_prefs.set_string ("default-save-attachments-path", path);
     }
     path = opath = expand_download_dir (path.c_str(), self->_group.to_view());
-    if (path.find("%s") != path.npos)
+    if ((path.find("%s") != path.npos) || (path.find("%S") != path.npos))
       subject_in_path = true;
 
     // get the save mode
diff --git a/pan/usenet-utils/text-massager-test.cc b/pan/usenet-utils/text-massager-test.cc
index c64a3ef..0cd624d 100644
--- a/pan/usenet-utils/text-massager-test.cc
+++ b/pan/usenet-utils/text-massager-test.cc
@@ -369,59 +369,63 @@ void test_subj()
    const char *in2, *sep="_";
    in2 = "prefix - one ...__   - two - three";
    expected_out = "prefix_one_two_three";
-   out = pan::subject_to_path(in2, sep);
+   out = pan::subject_to_path(in2, false, sep);
    g_assert_cmpstr( out.c_str(), ==, expected_out.c_str());
    in2 = "prefix File 25 of 1000 one Post 1 _ 25: two file 1_10 end";
    expected_out = "prefix_one_two_end";
-   out = pan::subject_to_path(in2, sep);
+   out = pan::subject_to_path(in2, false, sep);
    g_assert_cmpstr( out.c_str(), ==, expected_out.c_str());
    in2 = "prefix [1 of 10] middle (2 / 20) end";
    expected_out = "prefix_middle_end";
-   out = pan::subject_to_path(in2, sep);
+   out = pan::subject_to_path(in2, false, sep);
    g_assert_cmpstr( out.c_str(), ==, expected_out.c_str());
    in2 = "prefix \" file name here\" yEnc ending";
    expected_out = "prefix";
-   out = pan::subject_to_path(in2, sep);
+   out = pan::subject_to_path(in2, false, sep);
    g_assert_cmpstr( out.c_str(), ==, expected_out.c_str());
    in2 = "prefix file name here yEnc ending";
    expected_out = "prefix_file_name";
-   out = pan::subject_to_path(in2, sep);
+   out = pan::subject_to_path(in2, false, sep);
    g_assert_cmpstr( out.c_str(), ==, expected_out.c_str());
    in2 = "prefix \"stuff \"\" file name here.sdf\" bar baz.gd ending";
    expected_out = "prefix_stuff_bar_ending";
-   out = pan::subject_to_path(in2, sep);
+   out = pan::subject_to_path(in2, false, sep);
    g_assert_cmpstr( out.c_str(), ==, expected_out.c_str());
    in2 = "prefix 2Kb one 3kB two 10 KB three 100 Bytes four [5 KB] end \t";
    expected_out = "prefix_one_two_three_four_end";
-   out = pan::subject_to_path(in2, sep);
+   out = pan::subject_to_path(in2, false, sep);
    g_assert_cmpstr( out.c_str(), ==, expected_out.c_str());
    in2 = "prefix / a \\ b < c > d | e * f ? g ' h \" end";
    expected_out = "prefix_a_b_c_d_e_f_g_h_end";
-   out = pan::subject_to_path(in2, sep);
+   out = pan::subject_to_path(in2, false, sep);
    g_assert_cmpstr( out.c_str(), ==, expected_out.c_str());
    in2 = "[foo]     K's    \"kpsh eg02b.jpg\" (0/2) 685k bar ";
    expected_out = "[foo]_K_s_bar";
-   out = pan::subject_to_path(in2, sep);
+   out = pan::subject_to_path(in2, false, sep);
    g_assert_cmpstr( out.c_str(), ==, expected_out.c_str());
    in2 = "[ASDF-FDSE]  Name1 & Name2 - Spettertje - 01 title here  (thx AntA)  Post 6_6 - File 9_9 - aaspettertje01.sfv (1/1)";
    expected_out = "[ASDF-FDSE]_Name1_&_Name2_Spettertje_01_title_here_(thx_AntA)";
-   out = pan::subject_to_path(in2, sep);
+   out = pan::subject_to_path(in2, false, sep);
    g_assert_cmpstr( out.c_str(), ==, expected_out.c_str());
    in2 = "Evil, Wicked Queen-e01.jpg(1/01)";
    expected_out = "Evil,_Wicked";
-   out = pan::subject_to_path(in2, sep);
+   out = pan::subject_to_path(in2, false, sep);
    g_assert_cmpstr( out.c_str(), ==, expected_out.c_str());
    in2 = "some text here...  and more... 123.jpg";
    expected_out = "some_text_here_and_more";
-   out = pan::subject_to_path(in2, sep);
+   out = pan::subject_to_path(in2, false, sep);
    g_assert_cmpstr( out.c_str(), ==, expected_out.c_str());
    in2 = "who are you? 123.jpg";
    expected_out = "who_are_you";
-   out = pan::subject_to_path(in2, sep);
+   out = pan::subject_to_path(in2, false, sep);
    g_assert_cmpstr( out.c_str(), ==, expected_out.c_str());
    in2 = "one - two three [1/2] - \"00 - title spaces.foo\" yEnc (1/5)";
    expected_out = "one_two_three";
-   out = pan::subject_to_path(in2, sep);
+   out = pan::subject_to_path(in2, false, sep);
+   g_assert_cmpstr( out.c_str(), ==, expected_out.c_str());
+   in2 = "one - two three [1/2] - \"00 - title spaces.foo\" yEnc (1/5)";
+   expected_out = "one_two_three_[1_2]_00_title_spaces.foo_yEnc_(1_5)";
+   out = pan::subject_to_path(in2, true, sep);
    g_assert_cmpstr( out.c_str(), ==, expected_out.c_str());
 }
 
diff --git a/pan/usenet-utils/text-massager.cc b/pan/usenet-utils/text-massager.cc
index 56fe1f9..083021a 100644
--- a/pan/usenet-utils/text-massager.cc
+++ b/pan/usenet-utils/text-massager.cc
@@ -449,12 +449,11 @@ TextMassager :: rot13_inplace (char * text)
 }
 
 std::string
-pan :: subject_to_path (const char * subjectline, const std::string &seperator)
+pan :: subject_to_path (const char * subjectline, bool full_subj, const std::string &seperator)
 {
   gchar *str1, *str2;
   const char *sep;
-  std::string val (subjectline);
-  //std::string::size_type pos;
+  std::string val;
   //stupid hack to silence the compiler
   GRegexCompileFlags cf0((GRegexCompileFlags)0);
   GRegexMatchFlags mf0((GRegexMatchFlags)0);
@@ -468,16 +467,18 @@ pan :: subject_to_path (const char * subjectline, const std::string &seperator)
     default : sep = "-"; break;
   }
 
-  // strip out newspost/Xnews-style multi-part strings
-  GRegex *mp1 =g_regex_new("\\s*(?:[Ff]ile|[Pp]ost)\\s[0-9]+\\s*(?:of|_)\\s*[0-9]+[:\\s]?", cf0, mf0, NULL);
-  str1 = g_regex_replace_literal(mp1, val.c_str(), -1, 0, " ", mf0, NULL);
-  g_regex_unref(mp1);
+  if(!full_subj)
+  {
+    // strip out newspost/Xnews-style multi-part strings
+    GRegex *mp1 =g_regex_new("\\s*(?:[Ff]ile|[Pp]ost)\\s[0-9]+\\s*(?:of|_)\\s*[0-9]+[:\\s]?", cf0, mf0, NULL);
+    str1 = g_regex_replace_literal(mp1, subjectline, -1, 0, " ", mf0, NULL);
+    g_regex_unref(mp1);
 
-  // and the rest.  the last check is for pans collapsed part count
-  GRegex *mp2 =g_regex_new("\\s*([\[(]?'?[0-9]+'?\\s*(?:of|/)\\s*'?[0-9]+'?.)|\\(/[0-9]+\\)", cf0, mf0, NULL);
-  str2 = g_regex_replace_literal(mp2, str1, -1, 0, "", mf0, NULL);
-  g_free(str1);
-  g_regex_unref(mp2);
+    // and the rest.  the last check is for pans collapsed part count
+    GRegex *mp2 =g_regex_new("\\s*([\[(]?'?[0-9]+'?\\s*(?:of|/)\\s*'?[0-9]+'?.)|\\(/[0-9]+\\)", cf0, mf0, NULL);
+    str2 = g_regex_replace_literal(mp2, str1, -1, 0, "", mf0, NULL);
+    g_free(str1);
+    g_regex_unref(mp2);
 
   // try to strip out the filename (may fail if it contains spaces)
   GRegex *fn =g_regex_new("\"[^\"]+?\" yEnc.*"    "|"
@@ -488,11 +489,14 @@ pan :: subject_to_path (const char * subjectline, const std::string &seperator)
   g_free(str2);
   g_regex_unref(fn);
 
-  // try to strip out any byte counts
-  GRegex *cnt =g_regex_new("\\[?[0-9]+\\s*(?:[Bb](ytes)?|[Kk][Bb]?)\\]?", cf0, mf0, NULL);
-  str2 = g_regex_replace_literal(cnt, str1, -1, 0, "", mf0, NULL);
-  g_free(str1);
-  g_regex_unref(cnt);
+    // try to strip out any byte counts
+    GRegex *cnt =g_regex_new("\\[?[0-9]+\\s*(?:[Bb](ytes)?|[Kk][Bb]?)\\]?", cf0, mf0, NULL);
+    str2 = g_regex_replace_literal(cnt, str1, -1, 0, "", mf0, NULL);
+    g_free(str1);
+    g_regex_unref(cnt);
+  }
+  else
+    str2 = g_strdup(subjectline);
 
   // remove any illegal / annoying characters
   GRegex *badc =g_regex_new("[\\\\/<>|*?'\"\\.\\s]+", cf0, mf0, NULL);
diff --git a/pan/usenet-utils/text-massager.h b/pan/usenet-utils/text-massager.h
index 68251db..e89f9e6 100644
--- a/pan/usenet-utils/text-massager.h
+++ b/pan/usenet-utils/text-massager.h
@@ -60,7 +60,7 @@ namespace pan
    *
    * @ingroup usenet_utils
    */
-   std::string subject_to_path (const char * subjectline, const std::string &seperator);
+   std::string subject_to_path (const char * subjectline, bool full_subj, const std::string &seperator);
 
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]